How do install openjdk and tomcat in ubuntu server

OK, here is the solution I found after searching lots of things: 

http://www.oschina.net/question/12_21632

https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-on-ubuntu-12-04

My system is a ubuntu 10.04 LTS (Lucid), the openjdk version is 1.6, and a tomcat 6. 

If you want to install tomcat6, make sure you have java installed first. You could check your java installation by typing

java -version

in your command line. If you see an error, you don't have java. 

Regarding to the difference between openjdk and sun java, please refer to this blog: http://www.cnblogs.com/RuiYan/p/4098630.html

 

Let's get started: 

1. Install OpenJDK (Yes, you could definitely install sun-java-jdk instead)

sudo apt-get install openjdk-6-jdk

 

2. Check the installation of OpenJDK

java -version 

# operation result: 
java version "1.6.0_33"
OpenJDK Runtime Environment (IcedTea6 1.13.5) (6b33-1.13.5-1ubuntu0.10.04)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)

 

3. Set JAVA_HOME environmental variable (also configure .bashrc file)

after you install OpenJDK, this directory will be created: /usr/lib/jvm/java-6-openjdk

So we set this directory as the JAVA_HOME environmental variable in ~:

sudo vim ~/.bashrc
# you can add the following in the end of bashrc file
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export CATALINA_HOME=/usr/local/tomcat6

# save and exit out of .bashrc file, make changes effective by restarting bashrc file

. ~/.bashrc

 

4. Download and Install Tomcat6

sudo wget http://mirrors.gigenet.com/apache/tomcat/tomcat-6/v6.0.41/bin/apache-tomcat-6.0.41.tar.gz
tar xvzf apache-tomcat-6.0.41.tar.gz
sudo mv apache-tomcat-6.0.41 /usr/local/tomcat6
sudo chmod -R 755 /usr/local/tomcat6

 

5. Set automatic start for Tomcat6 once the system starts

create a file under /etc/init.d/ using vim ( vim command cheat sheet: http://www.cnblogs.com/RuiYan/p/4093972.html ) 

sudo vim /etc/init.d/tomcat6

edit the file with the following content:

# Tomcat6 server auto-start script

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk

 

case $1 in
start)
sh /usr/local/tomcat6/bin/startup.sh
;;
stop)
sh /usr/local/tomcat6/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat6/bin/shutdown.sh
sh /usr/local/tomcat6/bin/startup.sh
;;
esac
exit 0

 

6. Set executable privilege 

sudo chmod 755 /etc/init.d/tomcat6
sudo ln -s /etc/init.d/tomcat6 /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat6 /etc/rc2.d/S99tomcat

 

7. Start Tomcat6

sudo sh /usr/local/tomcat6/bin/startup.sh

# operation result:
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar

 

8. Stop Tomcat6

sudo sh /usr/local/tomcat6/bin/shutdown.sh

 

After you finish all the above:

- go to your server ip:8080 if you are using a ubuntu server to check tomat

- go to http://localhost:8080 if you are using a local ubuntu desktop/laptop.

If you see this, you are good.  

posted @ 2014-11-18 00:02  Rui Yan  阅读(342)  评论(0编辑  收藏  举报