ECS 397A:

How to use ‘javadoc.exe’:

  1. Javadoc.exe is a utility which comes with Java SDK. This means that if you can compile java source code on a particular machine, you should be able to find javadoc.exe somewhere in that machine.
  1. Either by searching the hard disk, or by knowing the Java installation path, lets’ assume you find your javadoc.exe at “D:\abcd\java\bin\javadoc.exe”.
  1. Open a command window. Type in

set PATH=%PATH%;d:\abcd\java\bin\

Replace d:\abcd\java\bin\ with your own javadoc.exe path. This will allow you to run javadoc.exe in any directory in your system.

  1. Go to your project home directory, Type in

javadoc.exe *.java

You will index.html and other generated html files. These will be your javadoc files.

  1. You can also run javadoc.exe without any arguments, which will give you a guide on how to use javadoc.exe.

What you need to do with javadoc:

  1. You need to write your comments in a certain way so that javadoc can pick them up from your source codes and put them into the html files.
  1. The @param and @return tag in comment block of constructors or member functions of a class can provide javadoc with more detailed information. As example below, it actually specifies the arguments and returns of a constructor or member function.

Starting from V1.4, you will not be able to embed html tags with your argument as

@param <I> values </I> values is my param.

Compiling the above with javadoc will give you an error. Please refer to question C5 of to go around of this problem.

@param and @return tag examples:

/** This is my Class

* Description of your class

*/

Class MyClass {

Private int p;

/** Constructor of myClass

* @param a description of what a does, in this case,

* setting private member p to be a

* @return none

*/

public MyClass (int a) {

p=a;

}

/** This is my Func1

* Description of this function

* @param a integer a to be added with b

* @param b integer b to be added with a

* @return the sum of both arguments

*/

public int func1(int a, int b){

int c;

c=a+b;

}

}

3. Class and Member functions of your labs need to be documented similar with the example above. Each constructor or member function should have @param and @return tags for javadoc even if they are void or none.

Online tutorial from Pitt.edu

How to use ‘jar.exe’:

  1. jar.exe is another utility comes with Java SDK.
  1. Similar to the steps setting up ‘javadoc.exe’, you need to find where jar.exe is (should be in same directory as javadoc.exe)
  1. Setup your dos path with “set PATH=%PATH%;d:\abcd\java\bin\” (replace d:\abcd\java\bin\ with your path”
  1. Run jar.exe with no argument to see help, and run

jar –cvf lab1.jar *

to compress everything in current directory into lab1.jar file.

  1. to run a jar-packaged application file: (from sun website)

JAR Files as Applications - 1.2 platform only

In version 1.2 of the JDK software, you can run JAR-packaged applications with the Java interpreter. The basic command is:

java -jar jar-file

The -jar flag tells the interpreter that the application is packaged in the JAR file format.

Note: The -jar option is not available for interpreters prior to version 1.2 of the Java Development Kit.

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