我已经 ssh 进入我的服务器(Ubuntu 12.04),无论我为 JAVA_HOME 和 JRE_HOME 设置什么,tomcat6 都不想启动:
me@myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ echo $JAVA_HOME
/usr/lib/jvm/jdk-oracle.1.6.0_33/bin
me@myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ echo $JRE_HOME
/usr/lib/jvm/jdk-oracle.1.6.0_33/jre
me@myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ sudo service tomcat6 start
* no JDK found - please set JAVA_HOME
me@myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ export JAVA_HOME=/usr/lib/jvm/jdk-oracle.1.6.0_33
me@myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ sudo service tomcat6 start
* no JDK found - please set JAVA_HOME
me@myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ ls $JAVA_HOME
bin db jre LICENSE README.html register_ja.html src.zip
COPYRIGHT include lib man register.html register_zh_CN.html THIRDPARTYLICENSEREADME.txt
me@myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ ls $JAVA_HOME/bin
appletviewer HtmlConverter java javap jdb jps jstat native2ascii rmic serialver wsgen
apt idlj javac javaws jhat jrunscript jstatd orbd rmid servertool wsimport
ControlPanel jar javadoc jconsole jinfo jsadebugd jvisualvm pack200 rmiregistry tnameserv xjc
extcheck jarsigner javah jcontrol jmap jstack keytool policytool schemagen unpack200
我正在查看 tomcat6 的 init.d 脚本,我发现了一些搜索 openjdk 的自定义逻辑。我不想用openjdk,我特意装了oracle!这是 init.d 脚本的片段(不是我写的):
# this is a work-around until there is a suitable runtime replacement
# for dpkg-architecture for arch:all packages
# this function sets the variable OPENJDKS
find_openjdks()
{
for jvmdir in /usr/lib/jvm/java-7-openjdk-*
do
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-7-openjdk-common" ]
then
OPENJDKS=$jvmdir
fi
done
for jvmdir in /usr/lib/jvm/java-6-openjdk-*
do
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-6-openjdk-common" ]
then
OPENJDKS="${OPENJDKS} ${jvmdir}"
fi
done
}
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
# defined in $DEFAULT)
OPENJDKS=""
find_openjdks
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm"
# Look for the right JVM to use
for jdir in $JDK_DIRS; do
if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
JAVA_HOME="$jdir"
fi
done
export JAVA_HOME
我不得不从 /usr/lib/jvm 中删除 openjdk,因为愚蠢的 tomcat 一直在寻找并使用它,即使我的 JAVA_HOME 变量被设置为使用 oracle 的 java.util.
请帮忙?我不知道如何解决这个问题。我正在使用 maven,而 maven 与我设置 JAVA_HOME 变量的方式完美契合。
编辑:
我打开了 init.d tomcat 脚本并更改了这一行:
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm"
对此:
JDK_DIRS="/usr/lib/jvm/jdk-oracle.1.6.0_33 /usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm"
(我刚刚将我的路径添加/usr/lib/jvm/jdk-oracle.1.6.0_33
到字符串中)突然 tomcat 启动并使用我的 oracle java 运行。我想这行得通,但这不可能是最好的方法。
编辑:
斯蒂芬C:
me@myserver:/usr/lib/jvm$ sudo bash
root@myserver:/usr/lib/jvm# echo $JAVA_HOME
/usr/lib/jvm/jdk-oracle.1.6.0_33