Java 带有 tomcat 的 JDK 环境变量(Ubuntu 12.04)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18686105/
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
JDK environment variable ( Ubuntu 12.04) with tomcat
提问by yaming
In Ubuntu,i set jdk environment(JAVA_HOME,JRE_HOME), and java -version can use. but i can start up tomcat. some info :
在Ubuntu中,我设置了jdk环境(JAVA_HOME,JRE_HOME),java -version可以使用。但是我可以启动tomcat。一些信息:
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- At least one of these environment variable is needed to run this program
- JAVA_HOME 和 JRE_HOME 环境变量均未定义
- 运行此程序至少需要这些环境变量之一
environment set /etc/profile
环境设置/etc/profile
JAVA_HOME=/opt/jvm/java/jdk1.7.0_25
JRE_HOME=/opt/jvm/java/jdk1.7.0_25/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME
export JAVA_HOME
export JRE_HOME
export PATH
logs
日志
sunshanming@sunshanming-vm1:~$ sudo /opt/apache-tomcat-7.0.42/bin/startup.sh
[sudo] password for sunshanming:
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
sunshanming@sunshanming-vm1:~$ echo $JAVA_HOME
/opt/jvm/java/jdk1.7.0_25
sunshanming@sunshanming-vm1:~$ echo $JRE_HOME
/opt/jvm/java/jdk1.7.0_25/jre
sunshanming@sunshanming-vm1:~$ java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
采纳答案by d0x
Try to set the variables in setenv.sh
in tomcats bin
folder. Thats where you specify the environment for tomcat.
尝试setenv.sh
在 tomcatsbin
文件夹中设置变量。这就是您为 tomcat 指定环境的地方。
Just create this file in tomcat/bin/setenv.sh
只需在tomcat/bin/setenv.sh 中创建此文件
#!/bin/bash
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
export CATALINA_OUT=/var/log/tomcat/catalina.out
export CATALINA_PID=/var/log/tomcat/catalina.pid
You can also specify other env. vars for you application there.
您还可以指定其他环境。你在那里申请的 vars。
Note:They don't create this file by default. Otherwise it would be overwritten on an update.
注意:默认情况下,他们不创建此文件。否则它会在更新时被覆盖。
Update because of your comment:
由于您的评论而更新:
The problem is that the /etc/profile
is not loaded if you use sudo
.
问题是/etc/profile
如果您使用sudo
.
You can test it like this:
你可以这样测试:
# Write a variable SMALLTEST into the profile file
sudo su -c "echo \"export SMALLTEST=Hello World\" >> /etc/profile"
# create a small script (like your startup.sh) that read the variable
echo "echo Variable is set to: $SMALLTEST" > smalletst
chmod +x smalletst
# Execute the script with sudo
sudo ./smalletst
Variable is set to:
And you see that the env. var is not set.
你会看到 env. var 未设置。
Update 2:
更新 2:
If you like to let your tomcat run as a service, you should have a look to the /opt/tomcat/bin/daemon.sh
script. This you can put ti /etc/init.d/tomcat
and specify your env. in the setenv.sh.
如果你想让你的 tomcat 作为服务运行,你应该看看/opt/tomcat/bin/daemon.sh
脚本。这您可以放置 ti/etc/init.d/tomcat
并指定您的环境。在 setenv.sh 中。
回答by Ortwin Angermeier
With Ubuntu you don't have to modify anything for running tomcat, if you use the packages that ship with the Ubuntu repo.
使用 Ubuntu,如果您使用 Ubuntu 存储库附带的软件包,则无需修改任何内容来运行 tomcat。
Just type sudo apt-get install tomcat7
. That will install tomcat7
with all the needed dependencies.
只需输入sudo apt-get install tomcat7
. 这将安装tomcat7
所有需要的依赖项。
I recommend to not install anythingmanually(without the package system), if you don't have to.
如果您不需要,我建议不要手动安装任何东西(没有包系统)。
回答by Amit Kr
This is quite simple actually.
这其实很简单。
In startup.sh and shutdown.sh, just provide the JAVA_HOME system variable value -
在startup.sh和shutdown.sh中,只提供JAVA_HOME系统变量值——
export JAVA_HOME="/home/mxdev/java_stack/jdk1.8.0_77"
导出 JAVA_HOME="/home/mxdev/java_stack/jdk1.8.0_77"