Java Reference
In-Depth Information
Manifest
. A manifest is a list of passengers or an invoice of cargo for a ship. The meaning has
been generalized to a description of the contents of something, e.g. a jar file.
If you are using an IDE and you have told it which class has method
main
,
any time you run the program, execution starts by calling method
main
.
Executing a Java program from the command line
In a DOS window or a command-line window, navigate to a directory that
contains a file
Name.java
(say) that:
1. Has a static procedure
main
with one argument that is a
String
array.
2. Has been been compiled, so that there is a file
Name.class
.
Then, the following command executes a call to method
main
of class
java.
Name
. The command should not include the suffix
.class
or
.java
.
java Name
16.2
Stand-alone applications
A Java application may consist of many classes. If you want to give someone an
application, you have to give them all the
.class
files. That can be messy. Better
is to put the application in a single file that can be executed easily, perhaps by
double-clicking on its icon. You do this by making a
jar
file of the classes.
Jar
stands for Java ARchive —after
tar
files (TapeARchives) on Unix systems.
To make a jar file with name
app.jar
, open a DOS or command-line win-
dow and navigate to the directory where the
.java
and
.class
files are. Type in
the following command (note: if command
jar
is not available, you will have to
change your
path
. See the end of this Sec. 16.2):
jar -cf app.jar *.class
The “c” in
-cf
is for
create
. The “f” is for file, and it indicates that the name
of the file to create follows, in this case,
app.jar
. The “
*.class
” is expanded
to name all the
.class
files in the directory. So, this command makes up a jar
file named
app.jar
, which 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
CMain
. Then do the following:
(a) Make up a file
x.mf
that contains one line of text:
Main-class: CMain
The suffix on
x.mf
stands for
manifest
. Make sure you hit the enter key after typ-
ing the text in the file because it must have a carriage-return or line-feed in it.
You can create file
x.mf
in wordpad, notepad, DrJava, or any editor you want.
Make sure the file is in the same directory as file
app.jar
.
Search WWH ::
Custom Search