You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Anand HS <an...@gmail.com> on 2011/07/01 00:18:36 UTC

Re: Set Java VM arguments programmatically in Tomcat

I apologize for not being clearer.
Basically I would like not to use any batch scripts ( in Windows ) to set
CATALINA_OPTS, JAVA_OPTS etc.. , instead would like to do it through a
custom Java program and then hook up . To this effect, I was wondering if
there is a way to extend Bootstrap class of Tomcat to achieve it.
That said, I'm not sure if it is a recommended way to do it even since I was
trying to just explore if batch files are the only options for me to feed in
environment variables to Tomcat and Java.

Thanks,
Anand

On Thu, Jun 30, 2011 at 12:04 PM, Caldarale, Charles R <
Chuck.Caldarale@unisys.com> wrote:

> > From: Anand HS [mailto:anandhs@gmail.com]
> > Subject: Set Java VM arguments programmatically in Tomcat
>
> > I would like to set JVM  arguments like Xmx, Xms etc programmatically
> > and provide it to Tomcat at start up.
>
> Not quite sure what you mean by "programmatically" here, since the values
> must be set during JVM initialization, long before any Tomcat code runs.
>  You can write your own script that sets the CATALINA_OPTS variable and then
> invokes the regular Tomcat startup scripts.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you received
> this in error, please contact the sender and delete the e-mail and its
> attachments from all computers.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: Set Java VM arguments programmatically in Tomcat

Posted by Bill Miller <mi...@gmail.com>.
I'd like to add a little bit specifically around setting the parameters for a Windows service.

It can be done, but as Chris pointed out, it's not easy. There are at least 2 ways I can think of off the top of my head to change the Windows service properties:
1. Write JNI code to call the appropriate Windows DLLs to access and update the registry. Not fun... and potentially problematic because of security requirements.
2. Use Java to write a Windows .reg file that can be imported using an OS call to import the file. This is almost trivial to do but it's technically a bit of a kludge and has the same security problems (albeit a bit simpler) than option 1.

FYI: The advantage of a Windows service is that it can be made to start when the OS starts, which can be really handy... it can also be a pain depending on your requirements :).

The option we use is calling VBScript to do the registry changes, but that doesn't involve Java at all.

Bill

-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net] 
Sent: June 30, 2011 10:10 PM
To: Tomcat Users List
Subject: Re: Set Java VM arguments programmatically in Tomcat

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Anand,

On 6/30/2011 6:18 PM, Anand HS wrote:
> Basically I would like not to use any batch scripts ( in Windows ) to set
> CATALINA_OPTS, JAVA_OPTS etc.. , instead would like to do it through a
> custom Java program and then hook up.

You can do this, except that your Java program must launch /a second
JVM/ in order to set properties -- specifically ones such as heap sizes,
etc.

> To this effect, I was wondering if
> there is a way to extend Bootstrap class of Tomcat to achieve it.

No. By the time the Bootstrap code is called, the heap has been
configured and it's too late.

> That said, I'm not sure if it is a recommended way to do it even since I was
> trying to just explore if batch files are the only options for me to feed in
> environment variables to Tomcat and Java.

If you install Tomcat as a service, you can set those parameters in the
service definition (itself a small program that launches the JVM with
the proper parameters) and do anything you want.

But you'll never be able to do this in any practical way through Java code.

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

iEYEARECAAYFAk4NLJEACgkQ9CaO5/Lv0PDQkwCgpPUIvxzVxB72RHxgdFHUW1aO
LGoAnioYym9HOjaRA5tYH7CKfeKfg/Mk
=4skK
-----END PGP SIGNATURE-----

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


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


Re: Set Java VM arguments programmatically in Tomcat

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

Anand,

On 6/30/2011 6:18 PM, Anand HS wrote:
> Basically I would like not to use any batch scripts ( in Windows ) to set
> CATALINA_OPTS, JAVA_OPTS etc.. , instead would like to do it through a
> custom Java program and then hook up.

You can do this, except that your Java program must launch /a second
JVM/ in order to set properties -- specifically ones such as heap sizes,
etc.

> To this effect, I was wondering if
> there is a way to extend Bootstrap class of Tomcat to achieve it.

No. By the time the Bootstrap code is called, the heap has been
configured and it's too late.

> That said, I'm not sure if it is a recommended way to do it even since I was
> trying to just explore if batch files are the only options for me to feed in
> environment variables to Tomcat and Java.

If you install Tomcat as a service, you can set those parameters in the
service definition (itself a small program that launches the JVM with
the proper parameters) and do anything you want.

But you'll never be able to do this in any practical way through Java code.

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

iEYEARECAAYFAk4NLJEACgkQ9CaO5/Lv0PDQkwCgpPUIvxzVxB72RHxgdFHUW1aO
LGoAnioYym9HOjaRA5tYH7CKfeKfg/Mk
=4skK
-----END PGP SIGNATURE-----

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