Tomcat 5.0 - setting System properties for an application

I

icedogchi

I have been all over the place looking for a solution to my problem and
have so far come up empty handed.

I am running Apache Tomcat/5.0.28 on Windows and I have deployed an
application to it.

The application needs to read a system property to load it's
configuration files.

So far, I have done the following in the
%catalina_home%/bin/catalina.bat file:

1) set CATALINA_OPTS=-Denvironment=preview
2) set CATALINA_OPTS=-D"environment=preview"
3) set CATALINA_OPTS=-D'environment=preview'

None of these appear to make it to my application.

I have also done:
1) set JAVA_OPTS=-Denvironment=preview
2) set JAVA_OPTS=-D"environment=preview"
3) set JAVA_OPTS=-D'environment=preview'

and again, my application never finds that the system property has been
set.

I have tried starting tomcat as a service, and I have started Tomcat
from the command line. Even when I check the manager at
(http://<server>/manager/serverinfo) no system properties are
displayed.

This can't be this difficult to do, but I sure can't figure it out.
Would someone please post the super secret method to set a System
property in Tomcat so that my web application can see it?

Thanks!
 
I

icedogchi

Aha! I knew if I posted the question I'd figure it out.

IF you are running the startup and shutdown commands from the command
line in windows:
edit catalina.bat
set JAVA_OPTS=-D<key>="<value>"

IF you are running Tomcat 5 as a service:
Run %CATALINA_HOME%/bin/tomca5tw.exe

This opens a GUI and allows you to set a system property to the JVM.
 
T

Tom Dyess

Aha! I knew if I posted the question I'd figure it out.

IF you are running the startup and shutdown commands from the command
line in windows:
edit catalina.bat
set JAVA_OPTS=-D<key>="<value>"

IF you are running Tomcat 5 as a service:
Run %CATALINA_HOME%/bin/tomca5tw.exe

This opens a GUI and allows you to set a system property to the JVM.

I typically use web.xml for this. A popular one I employ is
debug=true/false. I don't know if this is feasable in your situation though.
 
B

Brian Munroe

Tom said:
I typically use web.xml for this. A popular one I employ is
debug=true/false. I don't know if this is feasable in your situation though.

I second what Tom is suggesting. By placing your environment variables
in the deployment descriptor (<appname>/WEB-INF/web.xml), you can
restrict which applications will have access to these variables. If
you define them in the JVM, you won't.

If you need to have global variables defined, you can place them in
$CATALINA_HOME/conf/web.xml.

You define them in web.xml like:

<env-entry>
<env-entry-name>buildString</env-entry-name>
<env-entry-value>20050601-38</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>

between the <web-app> </web-app> tag

and then you can access them in your code like:

<% Context env = (Context) new
InitialContext().lookup("java:comp/env"); %>
<%= "build: " + env.lookup("buildString") %>

Hope that helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top