How do I set a system property when using an executable jar (one with an entry of Main-Class: ClassName)?
Location: http://www.jguru.com/faq/view.jsp?EID=469352 Created: Aug 6, 2001 Modified: 2001-08-18 19:08:48.451 Author: Tim Rohaly (http://www.jguru.com/guru/viewbio.jsp?EID=10) Question originally posed by Cintia Aono (http://www.jguru.com/guru/viewbio.jsp?EID=231889 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 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 man