Using Common SDK Tools

     

appletviewer

The Java Applet Viewer command allows you to execute applets outside of the context of a Web browser. To view an applet, pass the URL of the HTML document with the embedded applet to the appletviewer program as an argument. If the document does not contain any applets, the program does nothing. The program will run each applet it finds in a separate window.

appletviewer recognizes applets embedded using the <object> , <embed> , and <applet> tags.

The following options are available:

  • -debug Starts the appletviewer using the Java debug program jdb, allowing you to debug applets.

  • -encoding encodingName Specifies the input HTML file encoding that should be used when reading the URL.

  • -Jjavaoption Passes the specified javaoption as an argument to the Java interpreter.

Usage : appletviewer [options] url file

jar

The JAR tool combines multiple files into a single compressed file called a Java ARchive. It uses the same compression algorithm as Zip files, which means that you can open JAR files using any standard Zip utility. Its primary purpose is to facilitate ease of distribution when managing complete applications. For example, you can bundle your entire application into a single JAR for distribution, and others can use it by simply dropping it into their classpath. Alternatively, a JAR file can be set to be self-executing, so that the freestanding application it contains can be run by double-clicking. Applets have made good use of JAR files, because they facilitate all of the classes in an application being downloaded at one time, which saves considerable HTTP traffic, and speeds execution. In addition, JAR files can be signed so that users can determine the application's author.

If you use UNIX, you will find it easy to begin working with the jar command, as its syntax is nearly identical to TAR.

Options

The following options are available for the jar command:

  • c Creates a new archive in a file named f , if f is also specified.

  • u Updates an existing JAR file when f is specified.

    For example,

    jar uf myApp.jar myClass.class updates the JAR file named myApp.jar by adding to it the class named myClass.class.

  • x Extracts the files and directories from JAR file f if f is specified, or the standard input if f is omitted. If input files are specified, only those files will be extracted; otherwise , all of the files in the directory will be extracted.

  • t Lists the table of contents in JAR file f if f is specified, or the standard input if f is omitted. If input files are specified, only those files and directories will be listed; otherwise, all of the files and directories will be listed.

  • i Generates index information for the specified JAR file and its dependents.

    For example,

     

     jar i myApp.jar 

    generates an index called INDEX.LIST in the specified JAR file.

  • f Specifies the name of the JAR file on which you want to perform an operation, such as create or update. The option f and the name of the JAR file must both be present if either one of them is present. Omitting f and JAR file accepts a JAR file from standard input (when you specify the x and t commands) or sends the JAR file to standard output (when using the c and u commands).

  • v Generates verbose output. That is, it tells you a lot about what it is doing as it does it.

  • That's a zero, not the capital letter o. It tells the JAR application not to use compression, but to simply store the files.

  • M If you specify the c or u commands, M prevents the creation of a Manifest file.

  • m Includes name : value pairs that are in the Manifest file located in META-INF/MANIFEST. MF. A name: value pair is added unless one already exists with the same name, in which case its value is updated. The m and f options must appear in the same order that Manifest and JAR file appear when typing the command.

  • -C dir Changes to the directory specified in dir temporarily during execution of the jar command while processing the following filesToAdd argument.

     

     jar uf myApp.jar -C classes . -C bin myClass.class 

    The preceding command updates myApp.jar by adding to it all of the files of any type in the classes directory and does not create a directory named classes in the jar. It then temporarily changes to the original directory (.) before changing to the bin directory to add the single class myClass.class to the JAR file.

  • -Joption Passes option to the underlying Java runtime, so possible values for option here are the same as the options available to be passed to the java launcher itself.

Typical Examples

The following is how you frequently will use the jar tool:

 

 % jar cf myApp.jar *.class 

This example takes all of the files in the current directory with a .class extension and bundles them into a resulting JAR file called myApp.jar. A Manifest entry is automatically created. A Manifest file stores meta-information regarding an application in the form of name : value pairs.

For executing a JAR file, see the next section.

java

The java tool launches Java applications. It starts a Java Runtime Environment, loads a specified class, and invokes that class' main method. You should use the class' fully qualified name. You may pass arguments to the application; any arguments that are not options passed.

Typical Examples

The following is how you frequently will use the java tool.

 

 % java -cp Main.class 

The java tool will look for the startup class and other necessary classes in three locations: the bootstrap classpath, the installed extensions, and the user classpath.

  • -client Selects the Java HotSpot Client Virtual Machine.

  • -server Selects the Java HotSpot Server Virtual Machine.

  • -classpath The user classpath.

  • -cp . Alternative method of specifying the -classpath option. Specifies a list of directories, JAR archives, and Zip archives to search for class files. Class path entries are separated by colons (:) on UNIX, Solaris and Linux, and a semi- colon (;) in Windows. Specifying -classpath or -cp overrides any setting of the CLASSPATH environment variable that might already exist. If neither -classpath nor -cp is used and CLASSPATH is not set, the user class path consists of the current directory (.).

  • -Dproperty=value Sets a system property value.

  • -d32 -d64 Specifies whether the program is to be run in a 32-bit or 64-bit environment. If neither -d32 nor -d64 is specified, the default is to run in a 32-bit environment, though this will likely change once 64-bit processors become more prevalent .

  • -enableassertions[:<package name>"..." :<class name> ] -ea[:<package name>"..." :<class name> ] Enables assertions.

  • -disableassertions[:<package name>"..." :<class name> ] -da[:<package name>"..." :<class name> ] Disables assertions (clever).

  • -enablesystemassertions “esa Enables assertions in all system classes.

  • -disablesystemassertions “dsa Disables assertions in all system classes.

  • -jar Executes an application encapsulated in a JAR file. The first argument to the call is the name of the JAR file containing the application. The manifest of the JAR file must contain a line like this: Main-Class: classnameContainingMainMethod . Using this option, the JAR file becomes the source of all user classes, and the runtime ignores other user class path settings.

  • -verbose -verbose:class Displays verbose information regarding each loaded class.

  • -verbose:gc Displays information regarding garbage collection events.

  • -verbose:jni Displays information about Java Native Interface method execution.

  • -version Displays information regarding version information. After the version info is displayed, the program exits.

  • -showversion Displays information regarding version information. After the version info is displayed, the program continues.

  • -? “help Displays the usage information in this section and exits.

  • -X Displays information regarding non-standard options and then exits. Non-standard options are not presented here.

Here is how to execute a program called "runme.jar" that has been bundled as a JAR:

 

 java jar runme.jar SomeArgument 

It is assumed that you have created a manifest file for this JAR indicating which class in the application contains the main method.



Java Garage
Java Garage
ISBN: 0321246233
EAN: 2147483647
Year: 2006
Pages: 228
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net