一、安裝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主頁面