How do I set a system property when using an executable jar (one with an entry of Main-Class: ClassName)?

Tim Rohaly

Just like with executing a program just use the the -D flag along with the -jar flag. Here is my test case:

public class property {
    public static void main(String[] args) {
        System.out.println("User-defined property = " +
Compile and run using
    java -Dmy.property=test property
and you'll get the results:
    User-defined property = test
Now create a manifest (call it manifest.mf) that contains only the line:
    Main-Class: property
as the first line, then jar up property.class with this manifest:
    jar cvfm property.jar manifest.mf property.class
Now try to run as an executable jar:
    java -Dmy.property=test -jar property.jar
and you'll get the same result.

Warning:Be sure the last line of the manifest file has a newline at the end.