import
) for
A.B.C
main()
.
public static void main(String[])
javac
and java
have to be told package location via the
classpath.
$ java -classpath A.jar:B.jar:C.jar A.main
|
|
-classpath P:P/j.jar
finds both, searching view
first.-classpath P/j.jar:P
finds both, searching j.jar
first.
jar
command manipulates jar files.
jar
is similar to Unixoid archiving tools like ar
and
tar
.
$ jar options arguments
t
jar
option lists a jar file’s
(table of) contents.
$ jar tf solitaireGUI.jar META-INF/ META-INF/MANIFEST.MF shared/Card.class shared/CardList.class [ blah blah blah ] shared/Talon.class shared/VarStack.class solitaireGUI/AppletFrame.class solitaireGUI/BadCardPileException.class [ blah blah blah ] solitaireGUI/TSApr141811.class solitaireGUI/utils.class $
solitaireGUI/utils.class
entry in the jar listing mean?
pkg/.../pkg/x.class
c jar
option creates a jar file.
c
gets all arguments unused by other options.
$ ls blue red $ jar cf j.jar blue/*.class red/*.class $ ls blue j.jar red $ jar tf j.jar META-INF/ META-INF/MANIFEST.MF blue/m.class red/m.class $
$ java -classpath eagles-wing.jar ???
Where's the class with main()
?
-classpath
too.
$ jar tf j.jar META-INF/ META-INF/MANIFEST.MF [ blah blah blah ] $
m jar
option adds a manifest to a jar file.
mf
option order matches the argument order.
Manifest-Version: 1.0
Main-Class: x
manifest line tells the JVM to run
x.main()
to start execution.
Main-Class:
-enabled jar files can be run with the -jar java
option.
$ java -jar eagles-wing.jar # execuion begins...
$ cat red/m.java package red; class hw { public static void main(String args[]) { System.out.println("hello world!"); } } $ javac red/m.java $ java red.hw hello world! $
$ jar cf hw.jar red/*class $ jar tf hw.jar META-INF/ META-INF/MANIFEST.MF red/hw.class $ mv red /tmp $ java red.hw Exception in thread "main" java.lang.NoClassDefFoundError: red/hw $ java -classpath hw.jar red.hw hello world! $ java -jar hw.jar Failed to load Main-Class manifest attribute from hw.jar $
$ cat manifest Manifest-Version: 1.0 Main-Class: red.hw $ jar cmf manifest hw.jar red/*class red/*class : no such file or directory $ jar xf hw.jar $ jar cmf manifest hw.jar red/*class $ java -jar hw.jar hello world! $