如何为多个Tomcat实例设置JAVA_HOME?

时间:2022-04-25 16:56:10

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 only have one value. I want to set JAVA_HOME for each Tomcat server.

我有2个Java Web项目。一个运行在JDK 1.5上,另一个运行在JDK 1.6上。我想在同一台计算机上运行它们,但JAVA_HOME环境变量只能有一个值。我想为每个Tomcat服务器设置JAVA_HOME。

11 个解决方案

#1


38  

place a setenv.sh in the the bin directory with

将setenv.sh放在bin目录中

JAVA_HOME=/usr/java/jdk1.6.0_43/
JRE_HOME=/usr/java/jdk1.6.0_43/jre

or an other version your running.

或者你正在运行的其他版本。

#2


20  

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

您可以做的一件事是修改catalina.sh(基于Unix)或catalina.bat(基于Windows)。

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:

在每个脚本中,您可以设置某些变量,只有在shell下创建的进程才会继承。因此,对于catalina.sh,请使用以下行:

export JAVA_HOME="intented java home"

And for windows use

并用于Windows使用

set JAVA_HOME="intented java home"

#3


13  

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

如果您是Windows用户,请将以下内容放在必须在Tomcat bin目录中创建的setenv.bat文件中。

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.

如果您是Linux用户,请将以下内容放在必须在Tomcat bin目录中创建的setenv.sh文件中。

JAVA_HOME=/usr/java/jdk1.6.x

#4


7  

Also, note that there shouldn't be any space after =:

另外,请注意= =之后不应有任何空格:

set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_27

#5


4  

You can add setenv.sh in the the bin directory with:

您可以在bin目录中添加setenv.sh:

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

export JAVA_HOME = $(readlink -f / usr / bin / java | sed“s:bin / java ::”)

and it will dynamically change when you update your packages.

它会在您更新包时动态更改。

#6


3  

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

在UNIX中我遇到了这个问题,我手动编辑了catalina.sh并输入了

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.

作为前2行。我尝试在/ etc / profile中设置JAVA_HOME,但它没有帮助。

This worked finally.

这终于奏效了。

#7


2  

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

基于Linux的Tomcat6应该有/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"
...

#8


2  

I had the same problem my OS is windows 8 and I am using Tomcat 8, I just edited the setclasspath.bat file in bin folder and set JAVA_HOME and JRE_HOME like this...

我有同样的问题我的操作系统是Windows 8,我使用的是Tomcat 8,我只是编辑了bin文件夹中的setclasspath.bat文件并设置了JAVA_HOME和JRE_HOME这样......

@echo off
...
...
set "JRE_HOME=%ProgramFiles%\Java\jre8"
set "JAVA_HOME=%ProgramFiles%\Java\jdk1.7.0_03"
...
...

@echo off ......设置“JRE_HOME =%ProgramFiles%\ Java \ jre8”设置“JAVA_HOME =%ProgramFiles%\ Java \ jdk1.7.0_03”......

and it works fine for me now......

现在它对我来说很好......

#9


2  

For Debian distro we can override the setting via defaults

对于Debian发行版,我们可以通过默认值覆盖设置

/etc/default/tomcat6

Set the JAVA_HOME pointing to the java version you want.

将JAVA_HOME设置为指向所需的java版本。

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

#10


2  

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):

我认为这是一种最佳实践(您可能在同一台计算机上有许多Tomcat实例,您希望每个Tomcat实例使用其他Java Runtime Environment):

如何为多个Tomcat实例设置JAVA_HOME?

如何为多个Tomcat实例设置JAVA_HOME?

This is manual inside file: catalina.sh

这是手动内部文件: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.

#11


0  

Just a note...

只是一张纸条......

If you add that code to setclasspath.bat or setclasspath.sh, it will actually be used by all of Tomcat's scripts you could run, rather than just Catalina.

如果将该代码添加到setclasspath.bat或setclasspath.sh,它实际上将由您可以运行的所有Tomcat脚本使用,而不仅仅是Catalina。

The method for setting the variable is as the other's have described.

设置变量的方法与其他人所描述的一样。

#1


38  

place a setenv.sh in the the bin directory with

将setenv.sh放在bin目录中

JAVA_HOME=/usr/java/jdk1.6.0_43/
JRE_HOME=/usr/java/jdk1.6.0_43/jre

or an other version your running.

或者你正在运行的其他版本。

#2


20  

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

您可以做的一件事是修改catalina.sh(基于Unix)或catalina.bat(基于Windows)。

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:

在每个脚本中,您可以设置某些变量,只有在shell下创建的进程才会继承。因此,对于catalina.sh,请使用以下行:

export JAVA_HOME="intented java home"

And for windows use

并用于Windows使用

set JAVA_HOME="intented java home"

#3


13  

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

如果您是Windows用户,请将以下内容放在必须在Tomcat bin目录中创建的setenv.bat文件中。

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.

如果您是Linux用户,请将以下内容放在必须在Tomcat bin目录中创建的setenv.sh文件中。

JAVA_HOME=/usr/java/jdk1.6.x

#4


7  

Also, note that there shouldn't be any space after =:

另外,请注意= =之后不应有任何空格:

set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_27

#5


4  

You can add setenv.sh in the the bin directory with:

您可以在bin目录中添加setenv.sh:

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

export JAVA_HOME = $(readlink -f / usr / bin / java | sed“s:bin / java ::”)

and it will dynamically change when you update your packages.

它会在您更新包时动态更改。

#6


3  

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

在UNIX中我遇到了这个问题,我手动编辑了catalina.sh并输入了

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.

作为前2行。我尝试在/ etc / profile中设置JAVA_HOME,但它没有帮助。

This worked finally.

这终于奏效了。

#7


2  

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

基于Linux的Tomcat6应该有/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"
...

#8


2  

I had the same problem my OS is windows 8 and I am using Tomcat 8, I just edited the setclasspath.bat file in bin folder and set JAVA_HOME and JRE_HOME like this...

我有同样的问题我的操作系统是Windows 8,我使用的是Tomcat 8,我只是编辑了bin文件夹中的setclasspath.bat文件并设置了JAVA_HOME和JRE_HOME这样......

@echo off
...
...
set "JRE_HOME=%ProgramFiles%\Java\jre8"
set "JAVA_HOME=%ProgramFiles%\Java\jdk1.7.0_03"
...
...

@echo off ......设置“JRE_HOME =%ProgramFiles%\ Java \ jre8”设置“JAVA_HOME =%ProgramFiles%\ Java \ jdk1.7.0_03”......

and it works fine for me now......

现在它对我来说很好......

#9


2  

For Debian distro we can override the setting via defaults

对于Debian发行版,我们可以通过默认值覆盖设置

/etc/default/tomcat6

Set the JAVA_HOME pointing to the java version you want.

将JAVA_HOME设置为指向所需的java版本。

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

#10


2  

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):

我认为这是一种最佳实践(您可能在同一台计算机上有许多Tomcat实例,您希望每个Tomcat实例使用其他Java Runtime Environment):

如何为多个Tomcat实例设置JAVA_HOME?

如何为多个Tomcat实例设置JAVA_HOME?

This is manual inside file: catalina.sh

这是手动内部文件: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.

#11


0  

Just a note...

只是一张纸条......

If you add that code to setclasspath.bat or setclasspath.sh, it will actually be used by all of Tomcat's scripts you could run, rather than just Catalina.

如果将该代码添加到setclasspath.bat或setclasspath.sh,它实际上将由您可以运行的所有Tomcat脚本使用,而不仅仅是Catalina。

The method for setting the variable is as the other's have described.

设置变量的方法与其他人所描述的一样。