Total Pageviews

Monday, 19 March 2012

关于安装jdk环境

1.如果你的linux系统是centos/fedora,则:
# wget http://download.oracle.com/otn-pub/java/jdk/7u3-b04/jdk-7u3-linux-i586.rpm
# rpm -ivh jdk-7u3-linux-i586.rpm

2.如果你的linux系统是debian/ubuntu,则:
# apt-get install sun-java6-jdk

3.如果你的linux系统是其他发行版,则:
# wget http://javadl.sun.com/webapps/download/AutoDL?BundleId=69465
# mv  AutoDL?BundleId=69465 jre-7u9-i586.tar.gz
# tar zxvf jre-7u9-i586.tar.gz
# cd  jre1.7.0_09
#./bin/java -version
显示:
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b04)
Java HotSpot(TM) Server VM (build 22.1-b02, mixed mode)

说明java已初步装好。还需指定JRE_HOME environment variable(JRE_HOME环境变量),否则的话直接去启动tomcat的话,会出现如下错误:
root@server # /root/apache-tomcat-7.0.26/bin/startup.sh
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
(参见http://forums.eukhost.com/f33/neither-java_home-nor-jre_home-environment-variable-defined-8716/)
输入命令:
# export JRE_HOME=/root/jre1.7.0_09
然后回车.现在export只是暂时生效了。下次重启vps,就得重新输入这条命令。所以还要把这个语句写到一个脚本里。我们可以把export JRE_HOME=/root/jre1.7.0_09加到/etc/rc.local里。(最好这样做:edit /etc/profile,add "export JRE_HOME=/root/jre1.7.0_09" to the end of /etc/profile).还需把/root/jre1.7.0_09/bin/java -version加到/etc/rc.local里.
现在就可以启动tomcat了:
/root/apache-tomcat-7.0.33/bin/startup.sh
Using CATALINA_BASE:   /root/apache-tomcat-7.0.33
Using CATALINA_HOME:   /root/apache-tomcat-7.0.33
Using CATALINA_TMPDIR: /root/apache-tomcat-7.0.33/temp
Using JRE_HOME:        /root/jre1.7.0_09/
Using CLASSPATH:       /root/apache-tomcat-7.0.33/bin/bootstrap.jar:/root/apache-tomcat-7.0.33/bin/tomcat-juli.jar

以上内容表明成功启动tomcat。
注意:在修改/etc/rc.local时,需按顺序加入如下3条命令:
/root/jre1.7.0_09/bin/java -version
export JRE_HOME=/root/jre1.7.0_09
/root/apache-tomcat-7.0.33/bin/startup.sh
(最好把这3条命令加在所有其他命令的前面)
 相关帖子:

how to set java's PATH variable?

http://briteming.blogspot.co.uk/2012/03/jdk7.html