java -cp Shorts.jar Shorts
A much nicer solution is to use the Main-class attribute, which is a way of embedding the name of the class to run inside the JAR. Then you can just run the application (in Java 2, at least) like this:
java -jar Shorts.jar
How do you do it? Normally, you would create the JAR something like this: jar cvf Shorts.jar *.class The trick to adding the Main-class attribute is defining an entirely separate file with the attribute definition. For instance, create the following one-line file and save it as extra.mf:
Main-class: Shorts
Now, to create the JAR, use this command line:
jar cvmf extra.mf Shorts.jar *.class
The m option reads information from the extra.mf file you just created and adds it to the manifest of the JAR you're creating. Now you can run the JAR using java -jar Shorts.jar.
No comments:
Post a Comment