Java Reference
In-Depth Information
Extracting Javadoc comments
Assume that you have placed Javadoc comments on classes, methods, and
fields (see Appendix II.2). To extract the Javadoc comments, type the following
mkdir doc
javadoc -d doc *java
(Note, in some systems, you may not have to create directory doc first; javadoc
will do it for you.) Program javadoc creates in directory doc a description of
your .java files in the same format as the API file specifications that you have
been looking at, where the description contains all the javadoc comments.
Bring up directory doc in a window (not a command-line window). Double
click on file index.html . Your browser will open with that file, and you will be
able to look at the specifications of your program. It's neat!
Making a stand-alone application
A program may consist of many classes, generally in the same directory. If you
want to give someone your program, you have to give them all the .class files
—zip them up into a .zip file— and the someone must then unzip them. That is
messy. To make things easier, you can make a jar file of the classes. Jar stands
for Java ARchive ; after tar files ( TapeARchives ) on Unix systems.
To make a jar file, get into a DOS or command-line window and navigate to
the directory where the .java and .clas s files are. Then, type in this command:
jar -cf file-name.jar *.class
The c is for create . The f is for file and indicates that the name of the file to
create follows: file-name.jar . The *.class is expanded to name all the .class
files in the directory. So, this command makes up a jar file named file-
name.jar that contains all the .class files in the directory.
You still have to insert into the jar file something that tells it which class has
method main. Suppose it is class MainClass . Then do the following:
(a) Make up a file that contains one line of text in it:
Main-class: MainClass
The suffix on stands for manifest . You do not have to use the suffix. Be sure
to hit the enter key after typing the text; there must be a carriage-return or line-
feed in it. You can create this file in wordpad or notepad or DrJava or any editor
you want. Make sure the file is in the same directory as file file-name.jar
(b) Type this command in the window:
jar -umf file-name.jar
The u stands for update , the m for manifest , and the f for file . Since the m comes
Search WWH ::

Custom Search