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
|