[csu540-f05-rpf] Working example of executable jars with subdirectories

Robert Futrelle futrelle at ccs.neu.edu
Sat Sep 17 11:58:38 EDT 2005


Self-contained notes by R P Futrelle on jarring, 9/17/05.
The numbered lines are command line
commands and what they returned.
(Done on my Mac, *not* checked on Solaris, sorry.)

There are three points to note:
A. The java source is in a package.
B. An executable jar is made for that class in the package.
C. A second jar is made that contains a Readme and also
    the original jar (nested jars, if you like).

Slightly edited trace of the command line,
in the directory FullProject --

  1 FullProject: cat Readme.txt
  2
  3 RPFutrelle 9/17/05
  4 There are TWO jars.
  5 One is made from the folder mypackage
  6 and references a MainClass: mypackage.HelloInPackage
  7 The other is made from the enclosing FullProject folder.
  8 None of this organization is made to be exemplary.
  9 It is only done to illustrate some of the various things
10 that can be done.
11
12 FullProject: ls -R
13 Readme.txt   full.mf     mypackage/     run.mf
14
15 ./mypackage:
16 HelloInPackage.class  HelloInPackage.java
17
18 FullProject: jar cmf run.mf run.jar mypackage/
19
20 FullProject: ls
21 Readme.txt  full.mf     mypackage/  run.jar     run.mf
22
23 FullProject: jar tf run.jar
24 META-INF/
25 META-INF/MANIFEST.MF
26 mypackage/
27 mypackage/.DS_Store
28 mypackage/HelloInPackage.class
29 mypackage/HelloInPackage.java
30
31 FullProject: java -jar run.jar
32 Hello from mypackage.HelloInPackage
33
34 FullProject: ls
35 Readme.txt  full.mf     mypackage/  run.jar     run.mf
36
37 FullProject: jar cmf full.mf full.jar run.jar Readme.txt
38
39 FullProject: jar tf full.jar
40 META-INF/
41 META-INF/MANIFEST.MF
42 run.jar
43 Readme.txt
44

COMMENTS ON THE ABOVE:

Line 12 shows the full contents, including in the mypackage folder
The class HelloInPackage starts with the line:
package mypackage;
so it's in the mypackage package and properly, in a folder of
the same name.

Line 18 shows the jarring to produce a runnable jar, run.jar,
using  manifest file run.mf:

Manifest-Version: 1.0
Created-By: 1.5.0_02 (Apple Computer, Inc.) and RPF
Main-Class: mypackage.HelloInPackage

Line 23 shows the contents of run.jar
Line 31 shows that the run.jar is executable, in spite
of the subdirectory involved, mypackage/

Line 37 creates another jar, full.jar which has as its contents
only the run.jar and the Readmet.txt.
Its manifest file, full.mf, is vanilla:

Manifest-Version: 1.0
Created-By: 1.5.0_02 (Apple Computer, Inc.) and RPF

Line 39 asks for the contents of the new full.jar,
which is as expected (Lines 40-43)

For completeness, here's the source of HelloInPackage.java:

-------------------------
package mypackage;

/**
  * Can be used in executable jar w. MainClass mypackage.HelloInPackage.
  * For class CSU540, Computer Graphics, Fall 2005
  * Northeastern U., Boston, MA
  * @author R P Futrelle
  * @version 1 9/17/2005
  */

  public class HelloInPackage {
	 public static void main(String[] args){
		 System.out.println("Hello from mypackage.HelloInPackage");
	 }
  }
-------------------------

Note on spelling: Google says "jaring" is slightly preferred over "jarring"
which I have used.  English pronunciation suggests that "jaring" would
rhyme with "scaring" (scare) but "scarring" would be pronounced as in scar.
So I'll go with the 'proper' English for now. Check answers.com if
you're curious.  I have a nice answers.com plugin such that I can highlight
any word in almost any app and some command keys will pop up the answers.com
window for that word  - nice.




More information about the csu540-f05-rpf mailing list