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.
2. Download the latest version of tomcat tomcat.apache.org , i downloaded Apache Tomcat 8.0.21
- sudo apt-get install openjdk-7-jdk
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
- I rename dowonload folder to "apache-tomcat"
- and move it to location /usr/local/apache-tomcat
- go to /usr/local/apache-tomcat/conf/tomcat-users.xml
- or you can edit from terminal sudo nano /usr/local/apache-tomcat/conf/tomcat-users.xml
- place below lines & save. [ctrl+^+x then press Y]
- <role rolename="manager-gui">
- <role rolename="admin-gui">
- <user password="rohit" roles="manager-gui,admin-gui" username="rohit">
- </user>
- </role>
- </role>
4. Give 755 permission
- #!/bin/bash
- export CATALINA_HOME=/usr/local/apache-tomcat
- PATH=/sbin:/bin:/usr/sbin:/usr/bin
- start() {
- sh $CATALINA_HOME/bin/startup.sh
- }
- stop() {
- sh $CATALINA_HOME/bin/shutdown.sh
- }
- case $1 in
- start|stop) $1;;
- restart) stop; start;;
- *) echo "Run as $0
"; exit 1;; esac
5. For starting stoping tomcat
- sudo chmod 755 /etc/init.d/tomcat8021
6. We need to set Classpath and java home varibale to work properly. so i edited the file call environment place below lines there.
- sudo /etc/init.d/tomcat8021 start / stop
- sudo nano /etc/environment
- CLASSPATH=.:/usr/lib/jvm/default-java/bin:/usr/local/apache-tomcat/lib/servlet-api.jar
- JAVA_HOME=/usr/lib/jvm/default-java
Creating a new project in ubuntu 14.04 TLS
2. store(Project Folder) ---> WEB-INF ---> classes(DIR) , lib(DIR) , web.xml (file)
3. web.xml file looks like below
4. Inside classes folder your source file HelloWorld.java will be store for compiling it use below command
- <web-app>
- <servlet>
- <servlet-name>HelloWorld</servlet-name>
- <servlet-class>HelloWorld</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>HelloWorld</servlet-name>
- <url-pattern>/HelloWorld</url-pattern>
- </servlet-mapping>
- </web-app>
5. After compile .class file created by above command , then you need to create a context file ,
- mangel@mangel-desktop:/usr/local/apache-tomcat/webapps/store/WEB-INF/classes$
- javac -classpath /usr/local/apache-tomcat/lib/servlet-api.jar HelloWorld.java
- Go to cd /usr/local/apache-tomcat/conf/Catalina/localhost/ from terminal.
- sudo nano store.xml (store is the name of your project folder).
- Just paste below line
- <!-- Store Context -->
- <context debug="0" docbase="store" path="/store" reloadable="true">
- </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