如何为多个Tomcat实例设置JAVA_HOME?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1698913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set JAVA_HOME for multiple Tomcat instances?
提问by Chan Pye
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。
回答by bogertron
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"
回答by Ravi
Also, note that there shouldn't be any space after =
:
另外,请注意,后面不应有任何空格=
:
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_27
回答by rafeeq
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.
作为前两行。我尝试设置JAVA_HOME
in/etc/profile
但它没有帮助。
This worked finally.
这终于奏效了。
回答by Doug
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.
设置变量的方法如其他人所述。
回答by HowRude
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.
或您正在运行的其他版本。
回答by KCD
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"
...
回答by STB Land
If you are a Windowsuser, put the content below in a setenv.batfile that you must create in Tomcat bindirectory.
如果您是Windows用户,请将以下内容放入必须在 Tomcat bin目录中创建的setenv.bat文件中。
set JAVA_HOME=C:\Program Files\Java\jdk1.6.x
If you are a Linuxuser, put the content below in a setenv.shfile that you must create in Tomcat bindirectory.
如果您是Linux用户,请将以下内容放入必须在 Tomcat bin目录中创建的setenv.sh文件中。
JAVA_HOME=/usr/java/jdk1.6.x
回答by Tamil Selvan
I had the same problem my OS is windows 8 and I am using Tomcat 8, I just edited the setclasspath.batfile 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......
现在对我来说很好用......
回答by Paulo Fidalgo
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::")
导出 JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
and it will dynamically change when you update your packages.
它会在您更新软件包时动态更改。
回答by Shinu
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