日期:2014-05-16  浏览次数:20794 次

Linux中Tomcat和JDK安装及环境变量配置
1.在启动Tomcat时报的错误
 
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined解决
 
linux 下 启动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
 
先看Tomcat的startup.bat,它调用了catalina.bat,而catalina.bat则调用了setclasspath.bat。只要在setclasspath.bat的开头声明环境变量,打开tomcat的bin目录下面的setclasspath.sh,添加红色部分,路径自己修改。windows  下用set。
 
#!/bin/sh 
# -----------------------------------------------------
# Set CLASSPATH and Java options 
# 
# $Id: setclasspath.sh 467182 2006-10-23 23:47:06Z markt $ 
# ------------------------------------------------------
 
export JAVA_HOME=/usr/lib/jvm/java-7-sun 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(红色部分)
export JRE_HOME=/usr/lib/jvm/java-7-sun/jre 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(红色部分)
 
# First clear out the user classpath 
CLASSPATH= 
 
# Make sure prerequisite environment variables are set 
if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then 
# Bugzilla 37284 
if $darwin && [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home" ]; then 
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home" 
else 
echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined" 
echo "At least one of these environment variable is needed to run this program" 
exit 1 
fi 
fi 
if [ -z "$JAVA_HOME" -a "$1" = "debug" ]; then 
echo "JAVA_HOME should point to a JDK in order to run in debug mode." 
exit 1 
fi 
if [ -z "$JRE_HOME" ]; then 
JRE_HOME="$JAVA_HOME" 
fi 
 
# If we're running under jdb, we need a full jdk. 
if [ "$1" = "debug" -o "$1" = "javac" ] ; then 
if [ "$os400" = "true" ]; then 
if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then 
echo "The JAVA_HOME environment variable is not defined correctly" 
echo "This environment variable is needed to run this program" 
echo "NB: JAVA_HOME should point to a JDK not a JRE" 
exit 1 
fi 
else 
if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/jdb -o ! -x "$JAVA_HOME"/bin/javac ]; then 
echo "The JAVA_HOME environment variable is not defined correctly" 
echo "This environment variable is needed to run this program" 
echo "NB: JAVA_HOME should point to a JDK not a JRE" 
exit 1 
fi 
fi 
fi 

2.安装JDK
准备JDK安装包

   我下载安装的JDK是:jdk-6u29-linux-x64-rpm.bin

2.1上传或者拷贝到Linux系统中

   我拷贝到了/tmp目录下,如下图所示

   jdk包

2.2.给安装包jdk-6u29-linux-x64-rpm.bin加执行权限

   #cd /tmp

   #chmod +x jdk-6u29-linux-x64-rpm.bin

2.3.生成rpm文件(在/tmp目录下执行)

   #./jdk-6u29-linux-x64-rpm.bin

   现在的jdk安装包,执行到这里就完成安装了,如下图所示

   安装

   出现以上信息,你可以到目录下/usr/java下能找的安装好的jdk目录,我的如下图所示:

   jdk目录

   接下来可以跳过6~7步骤,直接进行8步的设置环境变量了。

2.4.给rpm文件jdk-6u29-linux-x64.rpm加执行权限(/tmp下执行)

   #chmod +x jdk-6u29-linux-x64.rpm

2.5.执行安装 (/tmp下执行)

   #rpm -ivh jdk-6u29-linux-x64.rpm

   根据提示信息,接受协议,执行一步步的安装即可。

2.6.设置环境变量(编辑文件/etc/profile):

   #vi /etc/profile

   在文件最后加上如下信息:

   设置环境变量

   JAVA_HOME=你的jdk安装的实际路径,我的安装在/usr/java目录下了。这个根据你的实际安装决定。
"环境变量设置"
vim /etc/profile
        #设置 jdk 的环境变量
        export JAVA_HOME=/usr/local/jdk
        export CLASSPATH=:$JAVA_HOME/lib
        export PATH=$PATH:$JAVA_HOME/bin

2.7检验安装配置是否成功:

   #java -version

   成功校验

   出现以上信息,说明安装已经成功!

3、Linux下的JDK卸载

3.1.卸载系统自带JDK版本

   #rpm -qa|grep gcj

   查看到如下信息,如图所示:

 &nbs