Tuesday, October 7, 2014

How to run a JAR file

You need to specify a Main-Class in the jar file manifest.
Sun's tutorial contains a complete demonstration, but here's another one from scratch. You need two files:
Test.java:
public class Test
{
    public static void main(String[] args)
    {
        System.out.println("Hello world");
    }
}
manifest.mf:
Manifest-version: 1.0
Main-Class: Test
Then run:
javac Test.java
jar cfm test.jar manifest.mf Test.class
java -jar test.jar
Output:
Hello world
http://stackoverflow.com/questions/1238145/how-to-run-a-jar-file

No comments:

Post a Comment