|
|
Applets Packaged in JAR Files
<applet code=TicTacToe.class width=120 height=120> </applet> If the TicTacToe demo were packaged in a JAR file named TicTacToe.jar, you could modify the APPLET tag with the simple addition of an ARCHIVE parameter: <applet code=TicTacToe.class archive="TicTacToe.jar" width=120 height=120> </applet> The ARCHIVE parameter specifies the relative path to the JAR file that contains TicTacToe.class. This example assumes that the JAR file and the HTML file are in the same directory. If they're not, you would need to include the JAR file's relative path in the ARCHIVE parameter's value. For example, if the JAR file was one directory below the HTML file in a directory called applets, the APPLET tag would look like this: <applet code=TicTacToe.class archive="applets/TicTacToe.jar" width=120 height=120> </applet> Applications Packaged in JAR Files - 1.1 platform
jre -cp app.jar MainClass In version 1.1 of the JDK software, the -cp option prepends the app.jar file to the system classpath. MainClass identifies the class within the JAR file that is the application's entry point. (Recall that in an application, one of the classes must have a method with the signature public static void main(String[] args) that serves as entry or starting point for the application.) JAR Files as Applications - 1.2 platform only
java -jar jar-file The -jar flag tells the interpreter that the application is packaged in the JAR file format.
Before this command will work, however, the runtime environment needs to know which class within the JAR file is the application's entry point. To indicate which class is the application's entry point, you must add a Main-Class header to the JAR file's manifest. The header takes the form: Main-Class: classname The header's value, classname, is the name of the class that's the application's entry point. To create a JAR file having a manifest with the appropriate Main-Class header, you can use the Jar tool's m flag as described in the Modifying a Manifest section. You would first prepare a text file consisting of single line with the Main-Class header and value. For example, if your application was the single-class HelloWorld application, the entry point would of course be the HelloWorld class, and your text file would have this line: Main-Class: HelloWorld Assuming your text file was in a file called mainClass, you could merge it into a JAR file's manifest with a command such as this: jar cmf mainClass app.jar HelloWorld.class With your JAR file prepared in this way, you can run the HelloWorld application from the command line: java -jar app.jar Applets Packaged in JAR Files
<applet code=TicTacToe.class width=120 height=120> </applet> If the TicTacToe demo were packaged in a JAR file named TicTacToe.jar, you could modify the APPLET tag with the simple addition of an ARCHIVE parameter: <applet code=TicTacToe.class archive="TicTacToe.jar" width=120 height=120> </applet> The ARCHIVE parameter specifies the relative path to the JAR file that contains TicTacToe.class. This example assumes that the JAR file and the HTML file are in the same directory. If they're not, you would need to include the JAR file's relative path in the ARCHIVE parameter's value. For example, if the JAR file was one directory below the HTML file in a directory called applets, the APPLET tag would look like this: <applet code=TicTacToe.class archive="applets/TicTacToe.jar" width=120 height=120> </applet> Applications Packaged in JAR Files - 1.1 platform
jre -cp app.jar MainClass In version 1.1 of the JDK software, the -cp option prepends the app.jar file to the system classpath. MainClass identifies the class within the JAR file that is the application's entry point. (Recall that in an application, one of the classes must have a method with the signature public static void main(String[] args) that serves as entry or starting point for the application.) JAR Files as Applications - 1.2 platform only
java -jar jar-file The -jar flag tells the interpreter that the application is packaged in the JAR file format.
Before this command will work, however, the runtime environment needs to know which class within the JAR file is the application's entry point. To indicate which class is the application's entry point, you must add a Main-Class header to the JAR file's manifest. The header takes the form: Main-Class: classname The header's value, classname, is the name of the class that's the application's entry point. To create a JAR file having a manifest with the appropriate Main-Class header, you can use the Jar tool's m flag as described in the Modifying a Manifest section. You would first prepare a text file consisting of single line with the Main-Class header and value. For example, if your application was the single-class HelloWorld application, the entry point would of course be the HelloWorld class, and your text file would have this line: Main-Class: HelloWorld Assuming your text file was in a file called mainClass, you could merge it into a JAR file's manifest with a command such as this: jar cmf mainClass app.jar HelloWorld.class With your JAR file prepared in this way, you can run the HelloWorld application from the command line: java -jar app.jar |