You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kaj Kandler <Ka...@conficio.com> on 2007/11/14 19:07:55 UTC

Setting Java property inside a webapp

Hi there,
I do have a library, that uses a property to determine some
configuration. As a straight Java program I would call

java -dmy.property=/my/value ...

How can I set this property in the context of a tomcat webapp, like in
the web.xml or context.xml?

Thanks for the help

K
-- 

*** Technical support for non technical users of OpenOffice.org ***
*** http://plan-b-for-openoffice.org/                           ***

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Setting Java property inside a webapp

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kaj,

Kaj Kandler wrote:
> Trickily I can't change the library (forgot to mention that), so I have
> to depend on the property value and can't change it to a JNDI lookup.
> 
> Well, I did the following:
> As I use Spring anyway, I created a bean property, that if set will also
> set the JVM property, not too great, but should work, as the value is
> global for all in the tomcat.
> 
> Any objections to this?


That's pretty much exactly what I suggested, except that you are using
Spring to do it instead of JNDI tricks to get things done.

Hackish? Yes. Useful? Yes!

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHO2tz9CaO5/Lv0PARAj0bAJoDXr/el0RtRM4c3hTlvlLbD4OB7gCfaPIR
xUuwgKdjAjn9oQPHMuKPq2U=
=XDfm
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Setting Java property inside a webapp

Posted by Kaj Kandler <Ka...@conficio.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thanks Christopher,
I appreciate the quick response.

Trickily I can't change the library (forgot to mention that), so I have
to depend on the property value and can't change it to a JNDI lookup.

Well, I did the following:
As I use Spring anyway, I created a bean property, that if set will also
set the JVM property, not too great, but should work, as the value is
global for all in the tomcat.

Any objections to this?

K
Christopher Schultz wrote:
> Kaj,
> 
> Kaj Kandler wrote:
>> Hi there,
>> I do have a library, that uses a property to determine some
>> configuration. As a straight Java program I would call
> 
>> java -dmy.property=/my/value ...
> 
>> How can I set this property in the context of a tomcat webapp, like in
>> the web.xml or context.xml?
> 
> Neither web.xml now context.xml will set system properties. You /can/
> have either of these files stick things into the JNDI context, though.
> 
> See
> http://tomcat.apache.org/tomcat-5.5-doc/config/globalresources.html#Environment
> Entries
> 
> for more information.
> 
> If you /need/ to use system properties, you could write a
> ServletContextListener to peek into JNDI and copy those values into he
> system properties of the JVM. Just remember that system properties are
> JVM-global, whereas JNDI resources are private to the application. If
> you deploy two applications with different settings within the same JVM,
> they will interfere with each other.
> 
> -chris

- ---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


- --

*** Technical support for non technical users of OpenOffice.org ***
*** http://plan-b-for-openoffice.org/                           ***
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)

iD8DBQFHO1D6RDUvrJRNjTARApZ1AJ99GF0fhQ5k5GqRma/8sy2mrYAx0ACdGxst
sEipX/PgkXhRwqHxjX1PB24=
=f30a
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Setting Java property inside a webapp

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kaj,

Kaj Kandler wrote:
> Hi there,
> I do have a library, that uses a property to determine some
> configuration. As a straight Java program I would call
> 
> java -dmy.property=/my/value ...
> 
> How can I set this property in the context of a tomcat webapp, like in
> the web.xml or context.xml?

Neither web.xml now context.xml will set system properties. You /can/
have either of these files stick things into the JNDI context, though.

See
http://tomcat.apache.org/tomcat-5.5-doc/config/globalresources.html#Environment
Entries

for more information.

If you /need/ to use system properties, you could write a
ServletContextListener to peek into JNDI and copy those values into he
system properties of the JVM. Just remember that system properties are
JVM-global, whereas JNDI resources are private to the application. If
you deploy two applications with different settings within the same JVM,
they will interfere with each other.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHOzum9CaO5/Lv0PARAsg8AJ4iWd60tShzFj7VShmzQRLe6z5y/ACgoURm
uoCEuQN83X9e+vQIyL4qfAA=
=Sc1s
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Setting Java property inside a webapp

Posted by Konstantin Kolinko <kn...@gmail.com>.
For tomcat you can define JAVA_OPTS system variable to supply
additional parameters for the java machine. That includes the
possibility to define -Dyour.property=

See the comments at the begin of catalina.bat or catalina.sh.
You can either modify catalina.bat/.sh or whatever bat file that is
used to start tomcat.

If you running Tomcat as a service (under Windows), the JVM options
are specified through the configuration dialog (on the Java tab of
it).

If you running Tomcat from an IDE, there are IDE-specific ways to
customize launching configuration and supply those options to java.


Of course, these settings are global for the tomcat instance. There
does not exist any way to specify different system property values for
different web applications.


Other tricks include modifying/updating system properties values on
the fly. As far as SecurityManager allows you to do that (IMHO, it
should not).


Best regards,
K.

2007/11/14, Kaj Kandler <Ka...@conficio.com>:
> Hi there,
> I do have a library, that uses a property to determine some
> configuration. As a straight Java program I would call
>
> java -dmy.property=/my/value ...
>
> How can I set this property in the context of a tomcat webapp, like in
> the web.xml or context.xml?
>
> Thanks for the help
>
> K
> --

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Setting Java property inside a webapp

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin,

Martin Gainty wrote:
> did you try setting the init-param in web.xml e.g.
> 
>         <init-param>
>             <param-name>my.property</param-name>
>             <param-value>1</param-value>
>         </init-param>

This is entirely unhelpful and has nothing to do with system properties. :(

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHO7DK9CaO5/Lv0PARAkS2AJwOgKk+WcbSXE4+RqB8lKmpnBP+ZQCePP4W
nNBun30SbObvFkrmh0NbE8s=
=WOlu
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org