How do I set a system property when using an executable jar (one with an entry of Main-Class: ClassName)?
Created May 7, 2012
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 = " + System.getProperty("my.property")); } }Compile and run using
java -Dmy.property=test propertyand you'll get the results:
User-defined property = testNow create a manifest (call it manifest.mf) that contains only the line:
Main-Class: propertyas the first line, then jar up property.class with this manifest:
jar cvfm property.jar manifest.mf property.classNow try to run as an executable jar:
java -Dmy.property=test -jar property.jarand you'll get the same result.
Warning:Be sure the last line of the manifest file has a newline at the end.