How to add jvm options to tomcat on windows 7

前端 未结 3 1755
心在旅途
心在旅途 2021-02-10 07:59

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

相关标签:
3条回答
  • 2021-02-10 08:47

    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

    1. Set the environment variable - project.home in windows environment using this link. Now, your env variable is set
    2. 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.

    0 讨论(0)
  • 2021-02-10 08:52

    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.

    0 讨论(0)
  • 2021-02-10 08:57

    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.

    0 讨论(0)
提交回复
热议问题