Monday, 30 November 2015

Install and Run Tomcat windows

I am explaining every step to run tomcat in window and how to setup your projects and running Servlets.

1. Install JDK before installing tomcat.

  a) I installed JDK1.6.0 onC:\Java\jdk1.6.0

NOTE: Do not installed JDK under C:\Program Files. I just faced problem after setting my
environment variable on Window Xp.

2. Download the latest version of tomcat.
tomcat.apache.org , i downloaded Apache Tomcat 7.0.65.I rename downloaded folder to "apache-tomcat" and placed it at E:\apache-tomcat.Go to "Start" --> "My Computer" --> Right click--> "Property"--> Click "Advance Tab" --> "Environment Variables" --> Opens a window where you have to create new Environment Variables As Written Below
  1. /* Under User Variable click New */
  2. Variable Name CATALINA_HOME
  3. Variable Value E:\apache-tomcat , Press ok
  4. Variable Name JAVA_HOME
  5. Variable Value C:\Java\jdk1.6.0, Press ok
  6. Variable Name JAVA_HOME
  7. Variable Value C:\Java\jdk1.6.0, Press ok
  8. Variable Name PATH
  9. Variable Value C:\Java\jdk1.6.0\bin, Press ok
  10. // Under System Variable click New
  11. Variable Name CALSSPATH
  12. Variable Value C:\Java\jdk1.6.0\bin;E:\apache-tomcat\lib\servlet-api.jar, Press ok
3. Now We have to edit configuration files E:\apache-tomcat\conf folder
  1. Open file context.xml find line/xml tag <Context>
  2. and replace by <Context reloadable="true">
  3. <servlet>...</servlet> inside this tag find
  4. <param-value>false</param-value>
  5. and replace with <param-value>true</param-value>
  6. Open file tomcat-users.xml and placed below code inside<tomcat-users>...</tomcat-users>
  1. <role rolename="manager-gui"/>
  2. <role rolename="admin-gui"/>
  3. <user username="boy108zon" password="boy108zon" roles="manager-gui,admin-gui"/>
4.Restart your computer. After above steps configuration. Lets create a new project.

1. I created a folder called store in E:\apache-tomcat\webapps\
2. Create Structure under
  1. store(Project Folder) ---> WEB-INF(DIR) --> classes(DIR) , web.xml (FILE)
  2. classes(DIR)-->HelloWorld.java (File)
3. Placed below xml code in web.xml created as above
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  3. "http://java.sun.com/dtd/web-app_2_3.dtd">
  4. <web-app>
  5. <servlet>
  6. <servlet-name>HelloWorld</servlet-name>
  7. <servlet-class>HelloWorld</servlet-class>
  8. </servlet>
  9. <servlet-mapping>
  10. <servlet-name>HelloWorld</servlet-name>
  11. <url-pattern>/</url-pattern>
  12. </servlet-mapping>
  13. </web-app>
4. Open http://localhost:8080/ You can see Tomcat Statup Page , you can click on Mange App it will ask you to enter username and password , As you putted OR placed in tomcat-users.xml.
 
Here you can see list of Application running or deploy. if you further check our created application also visible to this list , you can Start , Stop , Reload , Undeploy your application here. Click on start so that our created application can be start.
 
5. That's all , Now open http://localhost:8080/store/ and you will see your HelloWorld Running.