我的 tomcat 使用了错误的 JAVA_HOME 或 JRE_HOME

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

my tomcat uses wrong JAVA_HOME or JRE_HOME

javalinuxtomcatubuntu

提问by llch

I'm new to Tomcat. their is something wrong about Tomcat 7 on my ubuntu 10.10.

我是 Tomcat 的新手。他们在我的 ubuntu 10.10 上的 Tomcat 7 有问题。

when I start Tomcat like this

当我像这样启动Tomcat时

llchli@llchli-virtual-machine:/usr/local/apache-tomcat-7.0.47/bin$ ./catalina.sh  run
Using CATALINA_BASE:   /usr/local/apache-tomcat-7.0.47
Using CATALINA_HOME:   /usr/local/apache-tomcat-7.0.47
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.47/temp
Using JRE_HOME:        /usr/local/jdk1.7.0_45
Using CLASSPATH:       /usr/local/apache-tomcat-7.0.47/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.47/bin/tomcat-juli.jar

although cannot start Tomcat this way, it echos Using JRE_Home /usr/local/jdk1.7.0_45, which is the correct JAVA_HOMEor JRE_HOMEon my computer.

虽然无法以这种方式启动 Tomcat,但它会回应Using JRE_Home /usr/local/jdk1.7.0_45,这是正确的JAVA_HOMEJRE_HOME在我的电脑上。

but when I start Tomcat with sudolike this

但是当我sudo像这样启动Tomcat时

llchli@llchli-virtual-machine:/usr/local/apache-tomcat-7.0.47/bin$ sudo ./catalina.sh  start
[sudo] password for llchli: 
Using CATALINA_BASE:   /usr/local/apache-tomcat-7.0.47
Using CATALINA_HOME:   /usr/local/apache-tomcat-7.0.47
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.47/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/apache-tomcat-7.0.47/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.47/bin/tomcat-juli.jar

it echos Using JRE_HOME: /usr,which is not the correct JAVA_HOMEor JRE_HOMEon my computer. But it start Tomcat correctly.

它回响Using JRE_HOME: /usr,这不正确JAVA_HOMEJRE_HOME在我的电脑上。但它正确启动了Tomcat。

my /etc/environmentis

我的/etc/environment

llchli@llchli-virtual-machine:/usr/local/apache-tomcat-7.0.47/bin$ sudo cat /etc/environment 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/jdk1.7.0_45/bin"
LANGUAGE="en"
JAVA_HOME="/usr/local/jdk1.7.0_45"
CLASSPATH="$CLASSPATH:$JAVA_HOME/lib"
CATALINA_HOME="/usr/local/apache-tomcat-7.0.47"

I'm a bit puzzled about this.And when I use daemon.shlike this, it generate errors.

我对此有点困惑。当我这样使用时daemon.sh,它会产生错误。

llchli@llchli-virtual-machine:/usr/local/apache-tomcat-7.0.47/bin$ sudo ./daemon.sh run
Cannot find any VM in Java Home /usr
Cannot find any VM in Java Home /usr
Cannot locate JVM library file
Service exit with a return value of 1

It echos cannot find any VM in Java Home /usr. I'm so confused.

它回响cannot find any VM in Java Home /usr。我很困惑。

Any helps and advise will appreciate.

任何帮助和建议将不胜感激。

Thanks in advance.

提前致谢。

采纳答案by Stephen C

It sounds like "sudo" is not passing your JAVA_HOME and JAVA_PATH through to the child process.

听起来“sudo”没有将您的 JAVA_HOME 和 JAVA_PATH 传递给子进程。

When you run a command using "sudo" the environment variables are set according to what the sudoers file says. My reading of the "sudoers" manual entry is that the default is to NOT pass variables through. But according to the "sudo" manual entry, there is a command syntax variation that allows you to pass environment variables using "VAR=value" ...

当您使用“sudo”运行命令时,环境变量将根据 sudoers 文件的内容设置。我对“sudoers”手册条目的阅读是默认值是不传递变量。但是根据“sudo”手册条目,有一个命令语法变体,允许您使用“VAR=value”传递环境变量......

I suggest that you read the manual entries for "sudo" and "sudoers" carefully, and then read your system's "/etc/sudoers" file to understand how it is behaving.

我建议您仔细阅读“sudo”和“sudoers”的手册条目,然后阅读系统的“/etc/sudoers”文件以了解它的行为方式。



Having said that, launching services from the command line using "sudo" is not a good idea, especially if you are talking about "production" services. And you are generally better off using the service wrappers provided by your distro's packaging, rather than a non-packaged install from the "upstream" project.

话虽如此,使用“sudo”从命令行启动服务并不是一个好主意,尤其是当您谈论“生产”服务时。而且您通常最好使用发行版打包提供的服务包装器,而不是“上游”项目的非打包安装。

回答by Ortwin Angermeier

As i already state in a comment, i strongly suggest you to use the package system to install software, it it's available in the repository. (plus there are ppa's for nearly everything). That way you will keep your system tidy and you won't have worry about things not working (usually).

正如我在评论中已经指出的那样,我强烈建议您使用软件包系统来安装软件,它在存储库中可用。(另外几乎所有东西都有ppa)。这样,您将保持系统整洁,并且不必担心(通常)无法正常工作。

My suggestion is to remove your current manual install and install the tomcat7package.

我的建议是删除您当前的手动安装并安装该tomcat7软件包。

apt-get install tomcat7

For further configuration, use the file /etc/default/tomcat7. To start/stop/restart use the command service tomcat7 {start|stop|restart}.

如需进一步配置,请使用文件/etc/default/tomcat7. 要启动/停止/重新启动,请使用命令service tomcat7 {start|stop|restart}

Using the package tomcat7 the tomcat instance will run as it's own user, and notas root, and that's good, since a service should notrun as a user with full privileges.

使用包 tomcat7,tomcat 实例将以其自己的用户身份运行,而不是以 root身份运行,这很好,因为服务不应以具有完全权限的用户身份运行。

I am aware that i am actually not answering your question with the environment variables. But using the suggested way, you will not face that problem to begin with.

我知道我实际上并没有用环境变量回答你的问题。但是使用建议的方式,您一开始就不会遇到这个问题。

回答by JiLiang

Sudo resets the environment variables. When you run sudo, JRE_HOME is reset to its default (probably null) and Tomcat will assume its own default (/usr). You can run sudo with the -E switch to preserve the environment.

Sudo 重置环境变量。当您运行 sudo 时,JRE_HOME 被重置为其默认值(可能为 null)并且 Tomcat 将采用其自己的默认值 (/usr)。您可以使用 -E 开关运行 sudo 以保护环境。

Are you sure, you must run the script as root? I have no idea how to set up Tomcat, but it is usually a good practice to run servers as a dedicated user instead of as root.

您确定必须以 root 身份运行脚本吗?我不知道如何设置 Tomcat,但以专用用户而不是 root 身份运行服务器通常是一个好习惯。

回答by fometeo

it is all said, it means adding to /etc/sudoers a line with:

总而言之,这意味着在 /etc/sudoers 中添加一行:

Defaults env_keep += "JAVA_HOME JRE_HOME"

默认值 env_keep += "JAVA_HOME JRE_HOME"