Project

General

Profile

Installing Java and Tomcat » History » Revision 3

Revision 2 (Aleksander Bešir, 07.12.2010 13:03) → Revision 3/4 (Aleksander Bešir, 07.12.2010 13:03)

h1. Installing Java and Tomcat 

 Some of the following 

 h2. JDK installation 

 Before you install Tomcat you’ll want to make sure that you’ve installed Java. I would assume if you are trying to install Tomcat you’ve already installed java, but if you aren’t sure you can check with the dpkg command like so: 

 <pre> 
     dpkg –get-selections | grep openjdk 
 </pre> 

 This should give you this output if you already installed java: 

 <pre> 
     openjdk-6-jdk              install 
     openjdk-6-jre              install 
     ... 
 </pre> 

 If that command has no results, you’ll want to install the latest version with this command: 

 <pre> 
     sudo apt-get install openjdk-6-jdk 
 </pre> 

 h2. Apache Tomcat installation 

 Now we’ll download and extract Tomcat from the apache site. You should check to make sure there’s not another version and adjust accordingly. 
 <pre> 

     wget http://apache.hoxt.com/tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.14.tar.gz 

     tar xvzf apache-tomcat-6.0.29.tar.gz 
 </pre> 

 The best thing to do is move the tomcat folder to a permanent location. I chose /usr/local/tomcat, but you could move it somewhere else if you wanted to. 

 <pre> 
     sudo mv apache-tomcat-6.0.29 /usr/local/tomcat 
 </pre> 

 Tomcat requires setting the JAVA_HOME variable. The best way to do this is to set it in your .bashrc file. You could also edit your startup.sh file if you so chose. 

 The better method is editing your .bashrc file and adding the bolded line there. You’ll have to logout of the shell for the change to take effect. 

 <pre> 
     vi ~/.bashrc 
 </pre> 

 Add the following line: 

 <pre> 
     export JAVA_HOME=/usr/lib/jvm/java-6-openjdk 
 </pre> 

 At this point you can start tomcat by just executing the startup.sh script in the tomcat/bin folder. 

 h2. Automatic Starting 

 To make tomcat automatically start when we boot up the computer, you can add a script to make it auto-start and shutdown. 

 <pre> 
     sudo vi /etc/init.d/tomcat 
 </pre> 

 Now paste in the following: 

 <pre> 
     # Tomcat auto-start 
     # 
     # description: Auto-starts tomcat 
     # processname: tomcat 
     # pidfile: /var/run/tomcat.pid 

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

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

 You’ll need to make the script executable by running the chmod command: 

 <pre> 
     sudo chmod 755 /etc/init.d/tomcat 
 </pre> 

 The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way. 

 <pre> 
     sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat 
     sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat 
 </pre> 

 Tomcat should now be fully installed and operational.