Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

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

0
Posted

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

0

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

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123