Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set custom environment variables at startup??

Status
Not open for further replies.

Inandjo

Programmer
Dec 7, 2001
46
FR
Hi,

I am using tomcat 5.0 on a win2K box, and i cant seem to get an environment variable of mine to be set at startup.
The idea is that I would have a variable called VARIABLEG, that i could setup at tomcat startup, and then retrieve this variable later in a java program, the following way:
<code>
String var = System.getProperty("VARIABLEG");
System.out.println(var);
</code>
I tried by creating that variable in the startup.bat, by putting the following line, but it didn't work(I got a null value!!):
<code>set VARIABLEG=something</code>
I also googled it and found a way to do it by using the configure program under "apache software foundation" in the windows start/program files menu.
I added a line in the java options:
-DVARIABLEG=something
but that didn't work either.
I'm running out of options, and can't understand why such a simple thing is such a headach to get working!
Is there something I'm doing wrong, or am I just being plain dumb and stupid???

La faim justifie les moyens!
 
I would really advise against setting application level variables via the JVM.

If your application needs a variable, then you should add it the the webapp's web.xml really.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Thanx sedj, but would i still get to retrieve the variable via System.getProperty("Property_name");??
Thanx

La faim justifie les moyens!
 
No, you would use another method. For example, in web.xml :

Code:
<web-app>

  <context-param>
    <param-name>name</param-name>
    <param-value>value</param-value>
  </context-param> 

</web-app>

and in a servlet or JSP :

Code:
String value = getServletContext().getInitParameter("name");

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Thanx mate!!!

La faim justifie les moyens!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top