Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
1 jar-files 1.1 Summary Jar files are a way of packaging a java application as a single executable file. A jar file can contain bytecode (.class files) as well as data files, graphics images and other resources belonging to a java application. A jar-file is essentially a zip file with special features. You can easily view the contents of a jar file by renaming the file to .zip ( or adding the .zip extension) and the use software like WinZip of Windows XP’s internal. Zip file viewer. Zip tools cannot create jar files! Jar files contains features not implemented in standard zip tools. The purpose of this document is to provide a brioef description of jar-files and to provide an example of how a executable application in the form of a jar file can be created. 1.2 Thje structure of a jar file The netbeans environment creates jar-files whenever a project is successfully built. This example is given for the .jar file provided by netbeans building the KeyboardReading example. You find the jar file in your Project directory in the subdirectory named dist, see below. The jar-file is renamed with a .zip extension for easy viewing in WinXP. Thi zip-file displays the package created in the keyboardreading example, keyboardreading. 1.3 The jar manifest Most of the features provided by the jar format are contained within the folder META-INF. The META-INF folder contains metadata (information about the jar-file and the application). Nothing required by the application itself is located within this folder. The information is containg in a file called MANIFEST.MF. Manifest.mf is a plain text file with the .mf extension. The format of the Manifest.mf file is defined by jar. Example This instruction are created by the NetBeans environment. The information in the manifest is linebased key-value pairs. Manifestets form NAME: VALUE The key name/value pairs being Manifest-Version: 1.0 Main-Class: keyboardreading.KeyboardReading This provides the java environment with the instructions required to execute the application. In particular the class containing the public static void main(String[]arg) method. 1.4 Creating jar files You create a jar file by using the tool jar.exe. jar.exe is a command-line tool located in the java bin directory. Locate you java installation directory and locate the bin/jar.exe file. You command tool should have a path set to the java installation directory. Example 2 the help for creating the .jar file. Execute the command in your environment to get the help contents given in english. jar cvfm ApplicationName Mainfest-file Class-files Suppose we have written an application where the class containing the main method is named StartClass (of StartClass.class) and the required files, including StartClass.class, are located in a directory java. 1 – Create the manifest file using Notepad or similar suitable tool. The manifest must contain at a minimum. Manifest-Version: 1.0 Main-Class: StartClass Create this file in the same directory as the class files. 2 – Type the following command while in the directory java/ jar cvfm MyApplication.jar manifest.txt *.class The order of cvfm is important. c-create, v-verbose, f-file (supply a filename for the application/jar file), m-manifest(add a given manifest file). Something similar to the above will display.. The jar tool creates a file MyApplication.jar. You can execute this application by issuing the command java –jar MyApplication.jar 1.4.1 Configuring windows to execute –jar files You java install procedure may already have provoded you with this particular feature. If this is the case you shold not execute these instructions. In the explorer interface select menu Tools – select Folder Options – select tab File Types – select New... type jar and Ok. With the jar filetype selected select Advanced If the open action is nonexistent select New… If it exist select Edit… In the edit field Application used … navigate to your java installation directory. Select the java interpreter javaw.exe. Add the parameters -jar "%1" %* "C:\Program Files\Java\jre1.5.0_05\bin\javaw.exe" -jar "%1" %* or "C:\Program Files\Java\jre1.5.0_05\bin\java.exe" -jar "%1" %* Java.exe should be used if you would like to be able to execute console based applications. This will associate .jar files with the java runtime environment. Now your .jar files will be executable. You can execute you jar application file by double-clicking your .jar file or by writing start MyApplication.jar or just MyApplication.jar At a command prompt. The first statement will execute the application in a new process(own window in the console case), the second executes the application in the same console.