How can I add jvm options to Tomcat on Windows 7?. By the way I am using Tomcat 7. I added my jvm options to first line of catalina.bat
file but it didn't work. I think I am doing something wrong. Is there any idea?

- 4,555
- 1
- 23
- 36

- 5,393
- 25
- 82
- 148
-
2Try with file setenv.bat (add this file) – MariuszS Dec 18 '13 at 12:27
-
@MariuszS There is no file named setenv.bat? – hellzone Dec 18 '13 at 12:29
-
1As MariuszS said, you should add the file yourself and add the JVM options in there. Catalina.bat will check if this file exists and execute it. – Pieter Dec 18 '13 at 12:33
-
@Pieter I created a file named setenv.bat in bin directory and added set JAVA_OPTS=-Dproject.home=C:\Users\myproject but didn't worked. – hellzone Dec 18 '13 at 12:41
-
Do you get a specific error? Or could you describe in more detail what is not working? – Pieter Dec 18 '13 at 13:01
-
@Pieter It couldn't find the path for project.home – hellzone Dec 18 '13 at 14:24
-
@hellzone How are you starting your server? Can you post the complete command? – Pieter Dec 18 '13 at 14:31
-
Running as a service? http://stackoverflow.com/questions/6225682/passing-jvm-arguments-to-tomcat-when-running-as-a-service/6225719#6225719 – Michael Dec 18 '13 at 14:57
3 Answers
Create the file bin/setenv.bat
. If you are using bin/startup.bat
or bin/catalina.bat
to start Tomcat, then the setenv
script will be run before performing most other operations. You can set whatever JVM options you want by setting the CATALINA_OPTS
environment variable.
If you are using Tomcat's service launcher from Microsoft Windows' services panel to launch Tomcat then you cannot use this technique. Instead, you'll need to run tomcat7.exe
with the appropriate options you can find here.
Note that you can also set JAVA_OPTS
but JAVA_OPTS
will be used for all JVM processes, including the one launched to request a shutdown of Tomcat. For example, if you want to enable RMI services for Tomcat and you set them in JAVA_HOME
, then Tomcat will start up properly but when attempting to shutdown, the shutdown process may fail due to port conflicts. Similarly, if you need a 20GiB heap for Tomcat and you set -Xms
and -Xmx
in JAVA_OPTS
, you'll end up creating a 20GiB heap for the process that stops Tomcat. So, use CATALINA_OPTS
unless you have a very good reason to use JAVA_OPTS
.

- 20,221
- 9
- 60
- 77
Here you have my two cents,
Use CATALINA_OPTS or JAVA_OPTS. You can set the jvm options
in either one of these variables in catalina.bat
file according to your requirement. Read the comments in catalina.bat file about these variables. You will understand
EDIT after your comment
- Set the environment variable - project.home in windows environment using this link. Now, your env variable is set
Set the JAVA_OPTS in setenv.bat (you need to create this file)
set JAVA_OPTS="-Dproject.home"
or
set JAVA_OPTS="%JAVA_OPTS% -Dproject.home"
for safety purpose. This will prepend the existing JAVA_OPTS
with the new value.Start the server. Always, use UPPERCASE LETTERS, NUMBERS AND UNDERSCORE for environment variables. This is for portability reasons.

- 12,760
- 2
- 32
- 53
-
I read all comments in catalina.bat but I didn't understand anything. – hellzone Dec 18 '13 at 12:39
-
-
-
-
-
echo %java_home% works good it points jdk location but when i set variable name=a and value=b then I write echo %a% and It writes "%a%". I don't understand. – hellzone Dec 18 '13 at 14:55
-
can you execute set > env.txt in command prompt to list all environment variables. This command will write all the environment variables to env.txt in the same directory – Keerthivasan Dec 18 '13 at 14:58
-
-
1Change the environment variable 'Dproject.home' to 'project.home'. Remove the 'D' in the env variable name. but, don't forget that you should put -D while setting in the JAVA_OPTS to denote it is a user defined system variable – Keerthivasan Dec 18 '13 at 16:09
-
You should not modify `catalina.bat` (or `catalina.sh`). Instead, create a `bin/setenv.bat` (or `bin/setenv.sh`) file and set whatever options you need there. – Christopher Schultz Dec 19 '13 at 16:14
-
@ChristopherSchultz I have mentioned in the second point - Set the JAVA_OPTS in setenv.bat (you need to create this file) or catalina.bat file. – Keerthivasan Dec 19 '13 at 16:26
-
I prefer using context.xml
for tomcat environment variables:
File conf\context.xml
should looks like this:
<?xml version='1.0' encoding='utf-8'?>
<Context>
...
<Environment name="project.home" value="C:\Users\myproject" type="java.lang.String"/>
</Context>
After this environment variable project.home
is simply accessible inside your tomcat app.

- 30,646
- 12
- 114
- 155
-
1This won't work, because JVM options can't be set after the JVM launches. – Christopher Schultz Dec 19 '13 at 16:13
-
`project.home` looks like option for web application inside tomcat for me, but you are right, this is not working for JVM. – MariuszS Dec 19 '13 at 17:59