1、CentOS部署Java开发环境
一、安装jdk
jdk下载地址:http://www.Oracle.com/technetwork/java/javase/downloads/jdk-6u31-download-1501634.html
1.jdk上传到linux
[root@acong tools]# ll
total 167060
-rw-r--r-- 1 root root 85292206 Nov 8 2012 jdk-6u31-linux-i586.bin
-rw-r--r-- 1 root root 85581913 Oct 24 2012 jdk-6u31-linux-x64.bin
一个是32位的一个是64位的,以32位的为例
[root@acong tools]# mkdir /usr/local/java ##建立目录
[root@acong tools]# mv jdk-6u31-linux-i586.bin /usr/local/java/
移动软件包到/usr/local/java下
[root@acong tools]# cd /usr/local/java/
[root@acong java]# chmod 777 jdk-6u31-linux-i586.bin ##给安装包执行权限
[root@acong java]# ./jdk-6u31-linux-i586.bin ##安装出现Done 时安装成功
设置环境变量
[root@acong java]# vim /etc/profile
export JAVA_HOME=/usr/local/java/jdk1.6.0_31
export CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
[root@acong java]# source /etc/profile
验证java安装是否成功
[root@acong java]# java -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) Client VM (build 20.6-b01, mixed mode, sharing)
[root@acong java]# javac -version
javac 1.6.0_31
写个java程序运行测试下
[root@acong java]# javac HelloWorld.java
HelloWorld.java:2: cannot find symbol
symbol : class string
location: class HelloWorld
public static void main(string args[]){
^
HelloWorld.java:3: package system does not exist
system.out.println("hello world");
^
2 errors
提示有2处错误,很智能的可以看到哪里写错了。
在执行
[root@acong java]# javac HelloWorld.java
[root@acong java]# ll
total 83412
-rw-r--r-- 1 root root 425 Oct 11 19:46 HelloWorld.class
-rw-r--r-- 1 root root 109 Oct 11 19:46 HelloWorld.java
drwxr-xr-x 10 root root 4096 Oct 11 19:33 jdk1.6.0_31
-rwxrwxrwx 1 root root 85292206 Nov 8 2012 jdk-6u31-linux-i586.bin
看生成了.class文件
[root@acong java]# java HelloWorld
hello world
然后在在屏幕上打印出来 hello world了
二、安装tomcat
tomcat下载地址:
[root@acong java]# wget http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.26/bin/apache-tomcat-7.0.26.tar.gz
[root@acong java]# tar zxf apache-tomcat-7.0.26.tar.gz
[root@acong java]# mkdir /usr/local/tomcat
[root@acong java]# cp -ar apache-tomcat-7.0.26/* /usr/local/tomcat/
[root@acong java]# cd /usr/local/tomcat/bin/
[root@acong java]# chmod 777 startup.sh
[root@acong java]# chmod 777 catalina.sh
[root@acong bin]# ./startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java/jdk1.6.0_31
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
查看本机ip
浏览器中输入http://192.168.1.29:8080/
显示tomcat主页面