Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Tomcat 5.0 - setting System properties for an application

Thread view: 
icedogchi@yahoo.com - 21 Jun 2005 15:51 GMT
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!
icedogchi@yahoo.com - 21 Jun 2005 17:29 GMT
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.
Tom Dyess - 22 Jun 2005 02:12 GMT
> Aha!  I knew if I posted the question I'd figure it out.
>
[quoted text clipped - 7 lines]
>
> 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.

Signature

Tom Dyess
OraclePower.com

Brian Munroe - 22 Jun 2005 17:44 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.