basic jar commands:
jar tf MyApplication.jar
META-INF/
META-INF/MANIFEST.MF
com/
com/example
com/example/myapplication
com/example/myapplication/Echo.class
<http://docs.oracle.com/javase/tutorial/deployment/jar/build.html>
MANUAL METHOD to create a jar:
javac Echo.java
jar -cvf MyApplication.jar myapplicationfolder/
Use 7-zip to modify META-INF/MANIFEST.MF
Main-Class: pkg.to.mainclass.MainClassName
(followed by two newlines)
Sample very simple app which displays the command line parameters back to the console:
public class Echo {
public static void main (String[] args) {
for (String s: args) {
System.out.println(s);
}
}
}
From Eclipse it's fairly straightforward to Export a project (an all associated resources)
Leaving most settings to their defaults the key is the "export destination" (i.e. Browse)
TO RUN IT ON WINDOWS: java -classpath filename.jar Classname parameters
OR SHORTER:
if you don't want the extra command line parameters you have to put the Jar file in a location inside of your Classpath.
NOTE: you do have the option to pick which Class's main() is the default entry point,
in general if you leave it blank (i.e. only exporting one class) it will figure it out fine.
THEORETICALLY YOU CAN MAKE A "RUNNABLE JAR" in Eclipse quite easily:
1. Make sure you've used control f11 (i.e. RUN) at least once successfully in Eclipse in order to generate a
"launch configuration"
2. Right click and Export the Projectas a "runnable jar"
3. Ensure you choose the correct "launch configuration"
4. Then you can use the command line: java -jar filename.jar
Alternatives:
You must use the fully package qualified name. For example,
$ java -cp eharold.jar edu.poly.utopia.eharold.games.Trivia