简体   繁体   English

如何测试是否为Tomcat正确设置了JAVA_HOME-variable

[英]How to test if the JAVA_HOME-variable is set correctly for Tomcat

I'm currently setting up a Tomcat Server under Ubuntu 14.10. 我目前正在Ubuntu 14.10下设置Tomcat服务器。

in ${CATALINA_HOME}/RUNNING.txt it says, that either JAVA_HOME or JRE_HOME need to be set. ${CATALINA_HOME}/RUNNING.txt它表示需要设置JAVA_HOMEJRE_HOME I filled the file ${CATALINA_HOME}/bin/setenv.sh with: 我将文件${CATALINA_HOME}/bin/setenv.sh为:

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

since 以来

sudo dpkg -L 'openjdk-7-jdk'

indicated that this is the place where my JDK is installed. 表示这是我的JDK的安装位置。 To test the location, i also tried: 为了测试位置,我还尝试了:

JAVA_HOME=/usr/lib/jvm/some-none-existing-place

which gave no error when starting tomcat using ${CATALINA_HOME}/bin/startup.sh (although the path does obviously not exist) 使用${CATALINA_HOME}/bin/startup.sh启动tomcat时,这没有出错 (尽管该路径显然不存在)

So, when is this variable used by Tomcat and how can I check if I set the correct path (for Tomcat)? 那么,Tomcat何时使用此变量,如何检查是否为Tomcat设置了正确的路径?

Type in terminal, 输入终端,

echo $JAVA_HOME

It will display JAVA_HOME variable path. 它将显示JAVA_HOME变量路径。

IF nothing appears then you can set it manually by, 如果没有任何显示,则可以通过以下方式手动进行设置:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

This will differ according to your JDK type & version 这将根据您的JDK类型和版本而有所不同

Edit: Also you just follow the below to ensure you set in tomcat configuration file. 编辑:另外,您只需遵循以下内容以确保在tomcat配置文件中进行设置。

Hit Ctrl+Alt+T to open terminal and run: Ctrl+Alt+T打开终端并运行:

sudo gedit /etc/default/tomcat7

Find commented JAVA_HOME , uncomment and change the directory to your JDK environment. 查找已注释的JAVA_HOME ,取消注释并将目录更改为您的JDK环境。 Restart now and check for the error. 立即重新启动,并检查错误。

Open a command prompt, type : 打开命令提示符,键入:

java -version

java version "1.8.0_60" Java(TM) Java版本“ 1.8.0_60” Java(TM)

SE Runtime Environment (build > 1.8.0_60-b27) SE运行时环境(内部版本> 1.8.0_60-b27)

Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode) Java HotSpot(TM)64位服务器VM(内部版本25.60-b23,混合模式)

javac -version

javac 1.8.0_60 javac 1.8.0_60

echo %JAVA_HOME%

C:\\Program Files\\Java\\jdk1.8.0_60 C:\\ Program Files \\ Java \\ jdk1.8.0_60

So, what is your problem: 那么,您的问题是什么:
a) Tomcat does not start, or a)Tomcat无法启动,或者
b) it starts, but you do not know what version of Java it is using? b)它启动了,但是您不知道它使用的Java版本?

  1. Check that your setenv.sh file is readable. 检查您的setenv.sh文件是否可读。 If it is not readable, it will be ignored. 如果不可读,它将被忽略。

  2. If JRE_HOME variable is set then JAVA_HOME will be ignored. 如果设置了JRE_HOME变量,则将忽略JAVA_HOME。

    If neither one is set, then there are some defaults that are tried, including a call to which java . 如果未设置任何一个,则尝试使用一些默认值,包括对which java的调用。 (The magic is in ${CATALINA_HOME}/bin/setclasspath.sh). (魔术在$ {CATALINA_HOME} /bin/setclasspath.sh中)。

  3. The ${CATALINA_HOME}/bin/version.sh script will print the versions of Tomcat and Java. $ {CATALINA_HOME} /bin/version.sh脚本将打印Tomcat和Java的版本。

    Tomcat scripts print the actual value of JRE_HOME when Tomcat starts if you have a terminal. 如果您有终端,则在Tomcat启动时,Tomcat脚本会打印JRE_HOME的实际值。 ( if [ $have_tty -eq 1 ]; block in catalina.sh). if [ $have_tty -eq 1 ];在catalina.sh中阻止)。

    In recent versions of Tomcat a org.apache.catalina.startup.VersionLoggerListener can be configured in server.xml and will print the path to java and other settings. 在最新版本的Tomcat中,可以在server.xml中配置org.apache.catalina.startup.VersionLoggerListener并将其打印到Java和其他设置的路径。 http://tomcat.apache.org/tomcat-8.0-doc/config/listeners.html http://tomcat.apache.org/tomcat-8.0-doc/config/listeners.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM