How to set JAVA_HOME for multiple Tomcat instances?

前端 未结 11 1045
情话喂你
情话喂你 2020-12-14 06:29

I have 2 Java Web Projects. One runs on JDK 1.5 and the other runs on JDK 1.6. I want to run both of them on the same computer, but the JAVA_HOME environment variable can on

相关标签:
11条回答
  • 2020-12-14 06:48

    One thing that you could do would be to modify the catalina.sh (Unix based) or the catalina.bat (windows based).

    Within each of the scripts you can set certain variables which only processes created under the shell will inherit. So for catalina.sh, use the following line:

    export JAVA_HOME="intented java home"
    

    And for windows use

    set JAVA_HOME="intented java home"
    
    0 讨论(0)
  • 2020-12-14 06:49

    If you are a Windows user, put the content below in a setenv.bat file that you must create in Tomcat bin directory.

    set JAVA_HOME=C:\Program Files\Java\jdk1.6.x
    

    If you are a Linux user, put the content below in a setenv.sh file that you must create in Tomcat bin directory.

    JAVA_HOME=/usr/java/jdk1.6.x
    
    0 讨论(0)
  • 2020-12-14 06:50

    In UNIX I had this problem, I edited catalina.sh manually and entered

    export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.24
    echo "Using JAVA_HOME:       $JAVA_HOME"
    

    as the first 2 lines. I tried setting the JAVA_HOME in /etc/profile but it did not help.

    This worked finally.

    0 讨论(0)
  • 2020-12-14 06:56

    Linux based Tomcat6 should have /etc/tomcat6/tomcat6.conf

    # System-wide configuration file for tomcat6 services
    # This will be sourced by tomcat6 and any secondary service
    # Values will be overridden by service-specific configuration
    # files in /etc/sysconfig
    #
    # Use this one to change default values for all services
    # Change the service specific ones to affect only one service
    # (see, for instance, /etc/sysconfig/tomcat6)
    #
    
    # Where your java installation lives
    #JAVA_HOME="/usr/lib/jvm/java-1.5.0"
    
    # Where your tomcat installation lives
    CATALINA_BASE="/usr/share/tomcat6"
    ...
    
    0 讨论(0)
  • 2020-12-14 06:57

    I think this is a best practice (You may be have many Tomcat instance in same computer, you want per Tomcat instance use other Java Runtime Environment):

    This is manual inside file: catalina.sh

    #   JRE_HOME        Must point at your Java Runtime installation.
    #                   Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
    #                   are both set, JRE_HOME is used.
    
    0 讨论(0)
提交回复
热议问题