2

How do I, from Netbeans, for use with Tomcat, set up an environment variable that I can read using System.getProperty(...);

We have a source controlled project - and we're constantly making changes to confirurations that we "would" like to share (don't want to use svn:ignore). We're trying to set up one simple parameter, an environment variable to the config properties of our application. For example: mark.properties or john.properties. If the system can't find the environment variable, then it defaults to server.properties (for the live system).

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
sparkyspider
  • 13,195
  • 10
  • 89
  • 133

2 Answers2

13

1. Go to the Tomcat Properties Platform Settings

In Netbeans, click the "Services" tag. Under "Servers", you'll see "Tomcat 7.0". Right click "Tomcat 7.0" and select "Properties". Then select the "Platform" tab.

2. Under VM Options, add -Dvariable=value

Leave the D in place, and replace the variable with whatever variable name you'd like to set and value whatever value you'd like to set the variable to.

3. Read out the property from your code.

System.out.println("The value is " + System.getProperty("variable"));
sparkyspider
  • 13,195
  • 10
  • 89
  • 133
4

The answer is just in the NetBeans FAQ here:
http://wiki.netbeans.org/FaqSysPropsDuringRun

kbdjockey
  • 891
  • 6
  • 8
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Kalle Richter Jan 22 '17 at 01:20