apache Linux (centos) 上的 Tomcat。错误的Java版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1567597/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:16:32  来源:igfitidea点击:

Tomcat on Linux (centos). Incorrect java version

javalinuxapachetomcat

提问by LB.

I have installed Tomcat5 on CentOS 5 using the yum configuration tool. My java web application requires java 1.6 to run without errors. However, my tomcat install appears to be using java 1.4. This is confirmed when I navigate to the tomcat manager page:

我已经使用 yum 配置工具在 CentOS 5 上安装了 Tomcat5。我的 java web 应用程序需要 java 1.6 才能正常运行。但是,我的 tomcat 安装似乎使用的是 java 1.4。当我导航到 tomcat 管理器页面时,这一点得到确认:

Tomcat Version      JVM Version
Apache Tomcat/5.5.23    1.4.2

At the linux prompt, when I execute the command:

在 linux 提示符下,当我执行命令时:

java -version 

It reveals:

它揭示了:

java version "1.6.0"
OpenJDK  Runtime Environment (build 1.6.0-b09)
OpenJDK 64-Bit Server VM (build 1.6.0-b09, mixed mode)

I modifyied /etc/profile and setting JAVA_HOME, JRE_HOME, and CATALINA_HOME. When I execute tomcat5 versionthe following output results:

我修改了 /etc/profile 并设置了 JAVA_HOME、JRE_HOME 和 CATALINA_HOME。当我执行 tomcat5 version以下输出结果时:

Using CATALINA_BASE:   /usr/share/tomcat5
Using CATALINA_HOME:   /usr/share/tomcat5
Using CATALINA_TMPDIR: /usr/share/tomcat5/temp
Using JRE_HOME:       /usr/lib/jvm/jre-1.6.0
Server version: Apache Tomcat/5.5.23
Server built:   Jul 27 2009 05:24:08
Server number:  5.5.23.0
OS Name:        Linux
OS Version:     2.6.18-128.1.6.el5
Architecture:   amd64
JVM Version:    1.6.0-b09
JVM Vendor:     Sun Microsystems Inc.

However, when I start tomcat and view the server information the JVM still says:

但是,当我启动 tomcat 并查看服务器信息时,JVM 仍然说:

 JVM version 1.4.2

Any help is appreciated.

任何帮助表示赞赏。

Thanks,

谢谢,

回答by Rob Hruska

It looks like many people (both on CentOSand other platforms) have trouble with the yum-installed version of tomcat. I tried installing it myself, and tend to agree - it looks pretty messy.

看起来很多人(在CentOS其他平台上)都对 yum 安装的 tomcat 版本有问题。我尝试自己安装它,并且倾向于同意 - 它看起来很混乱。

Like others in the above links, I would recommend removing the yum version and downloading the tarball version straight from http://tomcat.apache.org/. I use this method for all of my tomcat installations (quite frequent), and have had few problems with this approach.

与上述链接中的其他人一样,我建议删除 yum 版本并直接从http://tomcat.apache.org/下载 tarball 版本。我将这种方法用于我所有的 tomcat 安装(非常频繁),并且这种方法几乎没有问题。

You can extract the tarball wherever you deem appropriate for your system (perhaps /opt), and start it up using the startup.shscript in the bin/directory. It should obey environment variables better than the yum version, but you can also set them in one of the properties files or scripts delivered with the application.

您可以将 tarball 提取到您认为适合您的系统的任何位置(可能/opt),然后使用目录中的startup.sh脚本启动它bin/。它应该比 yum 版本更好地遵守环境变量,但您也可以在与应用程序一起提供的属性文件或脚本之一中设置它们。

回答by habib00

try to set JAVA_HOME in /etc/sysconfig/tomcat5

尝试在 /etc/sysconfig/tomcat5 中设置 JAVA_HOME

回答by jarnbjo

If it is a regular Tomcat installation and you are not using any CentOS or yum specific scripts, you can set JAVA_HOME in bin/startup.sh (located in the Tomcat installation directory) to the installation directory of Java 6. This should force Tomcat to use the correct JDK installation.

如果是常规的 Tomcat 安装,并且您没有使用任何 CentOS 或 yum 特定脚本,则可以将 bin/startup.sh(位于 Tomcat 安装目录)中的 JAVA_HOME 设置为 Java 6 的安装目录。这应该会强制 Tomcat使用正确的JDK安装。

回答by Thomas Muench

try to edit the /usr/bin/dtomcat5script.

尝试编辑/usr/bin/dtomcat5脚本。