Monday, 11 May 2015

Tomcat 8.0.21 running in ubuntu 14.04 TLS

I am explaining every step to run tomcat in ubuntu 8.0.21 and how to setup your projects and running Servlets ,Jsp.
1. Install JDK 7 before installing tomcat.
  1. sudo apt-get install openjdk-7-jdk
2. Download the latest version of tomcat tomcat.apache.org , i downloaded Apache Tomcat 8.0.21
  1. I rename dowonload folder to "apache-tomcat"
  2. and move it to location /usr/local/apache-tomcat
  3. go to /usr/local/apache-tomcat/conf/tomcat-users.xml
  4. or you can edit from terminal sudo nano /usr/local/apache-tomcat/conf/tomcat-users.xml
  5. place below lines & save. [ctrl+^+x then press Y]
  6. <role rolename="manager-gui">
  7. <role rolename="admin-gui">
  8. <user password="rohit" roles="manager-gui,admin-gui" username="rohit">
  9. </user>
  10. </role>
  11. </role>
3. We have to create a bash file for running and stoping tomcat. Create a new file tomcat8021 in /etc/init.d/ and add the below code
  1. #!/bin/bash
  2. export CATALINA_HOME=/usr/local/apache-tomcat
  3. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  4. start() {
  5. sh $CATALINA_HOME/bin/startup.sh
  6. }
  7. stop() {
  8. sh $CATALINA_HOME/bin/shutdown.sh
  9. }
  10. case $1 in
  11. start|stop) $1;;
  12. restart) stop; start;;
  13. *) echo "Run as $0 "; exit 1;;
  14. esac
4. Give 755 permission
  1. sudo chmod 755 /etc/init.d/tomcat8021
5. For starting stoping tomcat
  1. sudo /etc/init.d/tomcat8021 start / stop
6. We need to set Classpath and java home varibale to work properly. so i edited the file call environment place below lines there.
  1. sudo nano /etc/environment
  2. CLASSPATH=.:/usr/lib/jvm/default-java/bin:/usr/local/apache-tomcat/lib/servlet-api.jar
  3. JAVA_HOME=/usr/lib/jvm/default-java

Creating a new project in ubuntu 14.04 TLS

1. I created a folder called store in /usr/local/apache-tomcat/
2. store(Project Folder) ---> WEB-INF ---> classes(DIR) , lib(DIR) , web.xml (file)
3. web.xml file looks like below
  1. <web-app>
  2. <servlet>
  3. <servlet-name>HelloWorld</servlet-name>
  4. <servlet-class>HelloWorld</servlet-class>
  5. </servlet>
  6. <servlet-mapping>
  7. <servlet-name>HelloWorld</servlet-name>
  8. <url-pattern>/HelloWorld</url-pattern>
  9. </servlet-mapping>
  10. </web-app>
4. Inside classes folder your source file HelloWorld.java will be store for compiling it use below command
  1. mangel@mangel-desktop:/usr/local/apache-tomcat/webapps/store/WEB-INF/classes$
  2. javac -classpath /usr/local/apache-tomcat/lib/servlet-api.jar HelloWorld.java
5. After compile .class file created by above command , then you need to create a context file ,
  1. Go to cd /usr/local/apache-tomcat/conf/Catalina/localhost/ from terminal.
  2. sudo nano store.xml (store is the name of your project folder).
  3. Just paste below line
  4. <!-- Store Context -->
  5. <context debug="0" docbase="store" path="/store" reloadable="true">
  6. </context>
So above all configure manually. just open locahost:8080/store/HelloWord.

No comments:

Post a Comment

If you have any doubt let me know