java 为什么 JAVA_HOME 在 Ubuntu 中无法被 tomcat7 识别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27457398/
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
Why JAVA_HOME not recognized by tomcat7 in Ubuntu?
提问by Omkar
I have installed tomcat7 on my Ubuntu machine. When I try to restart the server I get message to set JAVA_HOME but it is set in .bashrc
我已经在我的 Ubuntu 机器上安装了 tomcat7。当我尝试重新启动服务器时,我收到设置 JAVA_HOME 的消息,但它是在 .bashrc 中设置的
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export CATALINA_HOME=/usr/share/tomcat7
Error:
错误:
omkars@<ubuntu_14.04>:~$ sudo service tomcat7 restart
[sudo] password for omkars:
* no JDK or JRE found - please set JAVA_HOME
omkars@<ubuntu_14.04>:~$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
What could be missing ? Thanks.
可能缺少什么?谢谢。
回答by Omkar
Now, its working!
现在,它的工作!
Changes I have done are:
我所做的更改是:
- changed
.bashrc
as explained in the question. changed
/etc/init.d/tomcat7
to point to oracle Java8 which is missing here!JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-7-oracle **/usr/lib/jvm/java-8-oracle**"
.bashrc
如问题中所解释的那样更改。更改
/etc/init.d/tomcat7
为指向此处缺少的 oracle Java8!JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-7-oracle **/usr/lib/jvm/java-8-oracle**"
Then,
然后,
root@omkars-Dell-System-Inspiron-N4110:~# sudo service tomcat7 restart
* Starting Tomcat servlet engine tomcat7 [ OK ]
Got a hint from this page:
https://mifosforge.jira.com/wiki/display/MIFOSX/Install+Tomcat+7+on+Ubuntu+11.10+for+Mifos+X
从这个页面得到一个提示:https:
//mifosforge.jira.com/wiki/display/MIFOSX/Install+Tomcat+7+on+Ubuntu+11.10+for+Mifos+X
Thanks
谢谢
回答by Buzz Killington
It seems like the preferred way of handling this is to uncomment the JAVA_HOME entry in /etc/default/tomcat7
and adjust the path accordingly. If you're using the webupd8 repository with the oracle-java8-installer, it's JAVA_HOME=/usr/lib/jvm/java-8-oracle
.
似乎处理此问题的首选方法是取消注释 JAVA_HOME 条目/etc/default/tomcat7
并相应地调整路径。如果您将 webupd8 存储库与 oracle-java8-installer 一起使用,则它是JAVA_HOME=/usr/lib/jvm/java-8-oracle
.
回答by chiastic-security
It'll need to be set for the user that runs the tomcat service, rather than for your user.
它需要为运行 tomcat 服务的用户设置,而不是为您的用户设置。
Set it in the system wide profile, somewhere in /etc/profile
or /etc/profile.d/
, depending on how your machine is configured.
将其设置在系统范围的配置文件中,位于/etc/profile
或 中的某个位置/etc/profile.d/
,具体取决于您的机器的配置方式。
回答by Uriah Carpenter
The startup script at /etc/init.d/tomcat7
sources the file /etc/default/rcS
before searching for some well-known install locations.
在搜索一些众所周知的安装位置之前,启动脚本在/etc/init.d/tomcat7
源文件中/etc/default/rcS
。
Adding the line JAVA_HOME=/usr/lib/jvm/java-8-oracle
to /etc/default/rcS
corrects the no JDK or JRE found
startup problem without directly modifying the /etc/init.d/tomcat7
script.
添加行JAVA_HOME=/usr/lib/jvm/java-8-oracle
以/etc/default/rcS
更正no JDK or JRE found
启动问题,而无需直接修改/etc/init.d/tomcat7
脚本。
回答by Kuba Rakoczy
You can set an environmental variable in the setenv.sh
script. According to the Running The Apache Tomcat 7.0document:
您可以在setenv.sh
脚本中设置环境变量。根据运行 Apache Tomcat 7.0文档:
Apart from CATALINA_HOME and CATALINA_BASE, all environment variables can be specified in the "setenv" script. The script is placed either into CATALINA_BASE/bin or into CATALINA_HOME/bin directory and is named setenv.bat (on Windows) or setenv.sh (on *nix).
除了 CATALINA_HOME 和 CATALINA_BASE,所有环境变量都可以在“setenv”脚本中指定。该脚本放置在 CATALINA_BASE/bin 或 CATALINA_HOME/bin 目录中,并命名为 setenv.bat(在 Windows 上)或 setenv.sh(在 *nix 上)。
So just add the following line to setenv.sh
:
所以只需将以下行添加到setenv.sh
:
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
This way you are setting the variable locally.
这样您就可以在本地设置变量。
回答by sentechno
I have that same problem but I solve it by changing
JDK_DIR variable in /etc/init.d/tomcat
as follow :
我有同样的问题,但我通过如下更改 JDK_DIR 变量来解决它/etc/init.d/tomcat
:
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-7-oracle /usr/lib/jvm/java-8-oracle"
回答by Francesco Capodanno
Try install Java using the repository of http://www.webupd8.org.
尝试使用http://www.webupd8.org的存储库安装 Java 。
This is for Java 8: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html
这适用于 Java 8:http: //www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html