Chinaunix首页 | 论坛 | 博客
  • 博客访问: 316484
  • 博文数量: 90
  • 博客积分: 2850
  • 博客等级: 少校
  • 技术积分: 951
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-02 14:01
文章分类

全部博文(90)

文章存档

2015年(1)

2014年(1)

2013年(2)

2011年(3)

2010年(83)

分类: LINUX

2010-11-23 11:25:48


Linux下配置JDK与Tomcat

  先装JDK:

  #chmod +x jdk-1_5_0_02-linux-i586.rpm.bin

  #./jdk-1_5_0_02-linux-i586.rpm.bin
…………………….一篇协议………………………..
Do you agree to the above license terms? [yes or no] //这里选同意啦
yes //输入yes
解压文件………
……………………………..
Press Enter to continue..... //提示你按回车键继续
Done .


[root@rhel tomcat]# mv jdk-1_5_0_02/ /usr/local/ //把jdk安装在/usr/local目录里面
[root@rhel tomcat]# ln –s /usr/local/jdk-1_5_0_02 /usr/local/jdk1.5 //建立一个链接

//在/etc/profile里面添加以下内容
#vim /etc/profile
  JAVA_HOME=/usr/java/jdk-1_5_0_02

  CLASSPATH=.$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib.tools.jar:$JAVA_HOME/lib

#JRE_HOME=$JAVA_HOME/jre

  PATH=$JAVA_HOME/bin:$PATH

  export JAVA_HOME CLASSPATH PATH

[root@rhel ~]# source /etc/profile //重新载入profile文件

//下面是测试
[root@rhel ~]# java -version
java version "1.5.0_18-ea"
Java(TM) SE Runtime Environment (build 1.5.0_18-ea-b01)
Java HotSpot(TM) Client VM (build 16.0-b08, mixed mode, sharing)


  为了学习java,需要一个服务器,因此决定用比较流行的tomcat。根据网上对安装tomcat的介绍,自己进行了安装,现在已经成功了,现在把安装的过程进行记录,也供大家学习参考。

  一、从官方网站上下载tomcat软件包。

  

  点击左侧的 download的一个版本,我选择的是 tomcat6.x,你可以根据自己的实际情况进行选择安装,点击超连接,选择 Binary Distributions 下的tar.gz (pgp, md5) 压缩包,进行下载

  二、下载到本地后,进行解压

  #tar zxvf apach-tomcat-6.0.16.tar.gz

  #mv apach-tomcat-6.0.16 /usr/local

# ln -s /usr/local/ apache-tomcat-6.0.16 /usr/local/tomcat6.0


  三、进行tomcat环境的配置(前提需要安装jdk)

  #vi /etc/profile

  export JAVA_HOME=/usr/local/jdk1.6.0_04

  export TOMCAT_HOME=/usr/local/apach-tomcat-6.0.16

CATALINA_HOME=/usr/local/tomcat6.0

CATLINA_BASE=/usr/local/tomcat6.0

export TOMCAT_HOME CATALINA_HOME CATALINA_BASH

  保存退出

  # source /etc/profile //让当前配置立即生效

追加说明: 检查环境变量及JAVA版本
[root@rhel tomcat]# echo $JAVA_HOME
/usr/local/jdk1.6
[root@rhel tomcat]# echo $TOMCAT_HOME
/sr/local/tomcat6.0
[root@rhel tomcat]# echo $CLASSPATH
.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:/JAVA_HOME/lib
[root@rhel tomcat]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/ usr/local/jdk/bin:/root/bin //注意看一下/usr/local/jdk/bin是否已经写入PATH变量里面了。
[root@rhel tomcat]# java –version //查看JAVA的版本
java version "1.6.0_18-ea"
Java(TM) SE Runtime Environment (build 1.6.0_18-ea-b01)
Java HotSpot(TM) Client VM (build 16.0-b08, mixed mode, sharing)

//注意要确保以上的变量输出正常,


  四、启动tomcat服务器

  $ /usr/local/apach-tomcat-6.0.16/bin/startup.sh

  我的电脑上会出现如下内容:

  Using CATALINA_BASE: /usr/local/apache-tomcat-6.0.16

  Using CATALINA_HOME: /usr/local/apache-tomcat-6.0.16

  Using CATALINA_TMPDIR: /usr/local/apache-tomcat-6.0.16/temp

  Using JRE_HOME: /usr/local/jdk1.6.0_04

  五、在浏览器中输入就可以看到tomcat的log了(猫的欢迎页面)

  tomcat的安装到此结束。




2.tomcat安装的一些错误总结
————————分割线,我安装时出现下面的错误我记录下来了—————
[root@rhel ~]# sh /usr/local/tomcat/bin/startup.sh
The BASEDIR environment variable is not defined correctly
This environment variable is needed to run this program //大概意思就是说我的环境变量有错误;
[root@rhel bin]# export CATALINA_HOME=/usr/local/tomcat6.0 //建立一个环境变量,
[root@rhel bin]# echo $CATALINA_HOME
/usr/local/tomcat6.0
[root@rhel bin]# ./startup.sh
Cannot find /usr/local/tomcat6.0/bin/setclasspath.sh
This file is needed to run this program //汗,,,还不行,说找不到tomcat6.0这个目录,解决给/usr/local/tomcat给建立一个符号连接
root@rhel local]# ln -s /usr/local/tomcat/tomcat6.0
[root@rhel local]# cd tomcat/bin/
[root@rhel bin]# ./startup.sh
Using CATALINA_BASE: /usr/local/tomcat6.0
Using CATALINA_HOME: /usr/local/tomcat6.0
Using CATALINA_TMPDIR: /usr/local/tomcat6.0/temp
Using JRE_HOME: /usr/local/jdk/jre
touch: 无法触碰 “/usr/local/tomcat6.0/logs/catalina.out”: 没有那个文件或目录
/usr/local/tomcat/bin/catalina.sh: line 310: /usr/local/tomcat6.0/logs/catalina.out: 没有那个文件或目录
//提示无法创建/usr/local/tomcat6.0/logs/Catalina.out 这一个文件,因为没有logs这一个目录;
[root@rhel bin]# mkdir /usr/local/tomcat6.0/logs //给新建一个logs
[root@rhel bin]# ./startup.sh //再试一次
Using CATALINA_BASE: /usr/local/tomcat6.0
Using CATALINA_HOME: /usr/local/tomcat6.0
Using CATALINA_TMPDIR: /usr/local/tomcat6.0/temp
Using JRE_HOME: /usr/local/jdk/jre
测试发现tomcat没有启动
看日志:
——————————————————
[root@rhel bin]# cat /usr/local/tomcat6.0/logs/Catalina.out
xception in thread "main" java.lang.NoClassDefFoundError: org/apache/catalina/startup/Bootstrap
Caused by: java.lang.ClassNotFoundException: org.apache.catalina.startup.Bootstrap
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
Could not find the main class: org.apache.catalina.startup.Bootstrap. Program will exit.

重新下载tomcat6.0,下载非源码包的;

————————————————

[root@rhel tomcat]# cat /usr/local/tomcat6.0/logs/catalina.out
2009-8-27 0:05:35 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/local/jdk/jre/lib/i386/client:/usr/local/jdk/jre/lib/i386:/usr/local/jdk/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib //找不到库文件
2009-8-27 0:05:35 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2009-8-27 0:05:35 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 835 ms
2009-8-27 0:05:36 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2009-8-27 0:05:36 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.20
2009-8-27 0:05:36 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2009-8-27 0:05:37 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2009-8-27 0:05:37 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/33 config=null
2009-8-27 0:05:37 org.apache.catalina.startup.Catalina start
信息: Server startup in 1060 ms
问题: 找不到库文件
解决: 修改CLASSPATH=.:/usr/local/jdk1.6/lib/dt.jar:/usr/local/jdk1.6/lib/tools.jar:/usr/local/jdk1.6/lib

阅读(2266) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~