Computer Science 209 Software Development Jar Files for

  • Slides: 10
Download presentation
Computer Science 209 Software Development Jar Files for Applications and Libraries

Computer Science 209 Software Development Jar Files for Applications and Libraries

Byte Codes Everywhere! • The Java compiler creates a set of byte code files

Byte Codes Everywhere! • The Java compiler creates a set of byte code files (with a. class extension) • The main method’s byte code file can then be run with the java command • Library code, including package directories, must be placed in the current working directory

Jar files to the Rescue! • An entire application can be bundled in a

Jar files to the Rescue! • An entire application can be bundled in a single file with a. jar extension • This file can be launched by double-clicking or be run with the java command • A package can be bundled in a single file with a. jar extension, and placed in Java’s system directory for the use of any Java application

Creating an Executable Jar File Open a text editor and create a text file

Creating an Executable Jar File Open a text editor and create a text file named manifest. tmp. Include one line of code that specifies the main class name for the application. For example, if your main class is named Test. Student, enter the following code in this file: Main-Class: Test. Student

Creating an Executable Jar File For simple programs, place just the byte code files

Creating an Executable Jar File For simple programs, place just the byte code files in the same directory that includes manifest. tmp, and run the following command: > jar –cfm Test. Student. jar manifest. tmp *. class

Running an Executable Jar File Now, you can either launch the jar file by

Running an Executable Jar File Now, you can either launch the jar file by double-clicking on it or run it at the command line as follows: > java –jar Test. Student. jar

Creating a Jar File for a Library Place the package directory for the library

Creating a Jar File for a Library Place the package directory for the library in your current working directory. If there is more than one package involved, they must be organized in a hierary of subdirectories. Each directory should contain byte code files. You may include image files in appropriate subdirectories as well.

Creating a Jar File for a Library At the command prompt, run the jar

Creating a Jar File for a Library At the command prompt, run the jar command with the tag cvf, the name of the jar file, and the top-level package directory name. For example, if the package name is Breezy. Swing, you would run the command > jar cvf Breezy. Swing. jar Breezy. Swing

Using a Jar File for a Library Place the jar file in the appropriate

Using a Jar File for a Library Place the jar file in the appropriate system directory for Java on your computer. For example, on a Mac, this directory is <Your Hard Drive>/Library/Java/Extensions On a PC, these directories are C: Program FilesJavajre 1. 8. 0_144libext C: Program FilesJavajdk. 8. 0_144lib C: Program FilesJavajdk. 8. 0_144jrelibext