Foo.jar, you can run the program
it contains with the command:
java -jar Foo.jar
Decaying.java DrawArea.java Free.java L12.java Orbit.java Planet.java Straight.javaWe would compile this program like:
$ javac *.java... and run it like:
java L12... and, as a result, get a beautiful animation of a solar system!
Manifest.txt is
bundled together with all the .class files in the jar file. And
Manifest.txt has a line that states which class has the main()
method that should be called to kick off the program.
Suppose we have the solution to lab 12 shown in the note on the
right. The "main" is in L12.java. When we compile this we get
lots of .class files, so we would like to distribute this as a jar.
We create
a jar file by first creating the file Manifest.txt:
| Manifest.txt |
Main-Class: L12 |
jar cfm SolarSystem.jar Manifest.txt *.classThis creates the file SolarSystem.jar that we can send off to other people, who can run it (on any platform with a JVM) with the command:
java -jar SolarSystem.jarSince the "compiled" code is byte-code compiled for the JVM, rather than true machine-code, it can be run anywhere ... provided the host platform supports the version of Java you compiled to.
For your viewing pleasure, I've included SolarSystemA.jar and SolarSystemC.jar for you to run. Note: beware of running .jar files when you're not absolutely sure that a) the person who wrote it is on the up and up, and b) that you're really gotten the file you think you have!