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.
sudo apt-get install openjdk-7-jdk2. Download the latest version of tomcat tomcat.apache.org , i downloaded Apache Tomcat 8.0.21
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>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
#!/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 $04. Give 755 permission"; exit 1;; esac
sudo chmod 755 /etc/init.d/tomcat80215. For starting stoping tomcat
sudo /etc/init.d/tomcat8021 start / stop6. We need to set Classpath and java home varibale to work properly. so i edited the file call environment place below lines there.
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
<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>4. Inside classes folder your source file HelloWorld.java will be store for compiling it use below command
mangel@mangel-desktop:/usr/local/apache-tomcat/webapps/store/WEB-INF/classes$ javac -classpath /usr/local/apache-tomcat/lib/servlet-api.jar HelloWorld.java5. After compile .class file created by above command , then you need to create a context file ,
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