Java Reference
In-Depth Information
5.11.1.2
Let's assume we are going to manually put a Java application in a JAR file. We
will want to specify the name of the class that contains the main() method of
the application. First off, you want the JAR's directory hierarchy to begin at
the folder that contains the first node of each package's name. Our sample ap-
plication here is in the package net.multitool.Payback , so we want our
present working directory to be the one which contains the net subdirectory.
Here's a dump of the directory tree from that point after compilation of our
sample application:
Putting a Compiled Application in a JAR File
$ find . -print
.
./net
./net/multitool
./net/multitool/Payback
./net/multitool/Payback/Account.class
./net/multitool/Payback/Purchase.class
./net/multitool/Payback/Cost.class
./net/multitool/Payback/DebtAccount.class
./net/multitool/Payback/Payback.class
./net/multitool/Payback/SavingsAccount.class
./net/multitool/util
./net/multitool/util/SAMoney.class
./net/multitool/util/SAMoneyTest$1.class
./net/multitool/util/SAMoneyTest$2.class
./net/multitool/util/SAMoneyTest.class
$
We now want to specify which class contains the application's main()
method. It happens to be the Payback class, so we create a file called
manifest 28 with the following contents:
$ cat manifest
Main-Class: net.multitool.Payback.Payback
Next, we use the jar utility to create the JAR file:
28. It can have any name. The key/value pairs from the file will be placed by the jar utility into
the standard manifest called META-INF/MANIFEST.MF no matter what name you give to
this file.
Search WWH ::




Custom Search