set java home tomcat_如何為多個Tomcat實例設置JAVA_HOME?

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

aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9VS0VWbS5qcGc=

aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9UNGdXRS5qcGc=

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.

設置變量的方法與其他人所描述的一樣。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值