GreatWebGuy

Self-proclaimed greatness is a hard thing to prove

Setup Eclipse and Tomcat to play nice together

Eclipse is by far my favorite IDE, which makes Rational Application Developer bearable. The one thing I’ve been spoiled on in RAD is being able to run the WebSphere Test Environment inside the development environment and be able to have some level of hot deploy when modifying classes or jsp’s in the web project. This brings me to my problem with Eclipse and Tomcat, Eclipse provides great support for adding a Tomcat server to run in your IDE, but the default classpath set up forces you to do a build and restart almost everytime you modify a JSP or Class, this is a real pain. The other pain is that by default when you set up a web project, eclipse decides to build your src files into a build directory rather than just building them directly into the web project’s WEB-INF/classes directory.

This is what I’m here to solve. I’m assuming your using Eclipse 3.2 (Callisto) with the Web Tools installed, JDK 1.5 or 1.6, and Tomcat 5.5 or 6. May work in earlier versions, but I haven’t set up any projects like that recently.

Create a new Dynamic Web Project

  1. Open Eclipse
  2. Create a New Web Project
  3. Open the Java Perspective
  4. Right click and choose New -> Project
  5. Under Web Folder Choose Dynamic Web Project Click Next, Click Next
  6. Under Project Facets choose Dynamic Web Module, Java, Click Next
  7. Change Context Root to / Click Finish

Change the Build Path

  1. Right click the Project and choose Properties
  2. Choose Java Build Path in the Left Panel, Click the Source Tab
  3. Change the Default output folder to: yourprojectname/WebContent/WEB-INF/classes
  4. Click OK

Create Tomcat Server

  1. Right click and choose New -> Other
  2. Under Server Folder Choose Server Click Next
  3. Under Apache Choose Tomcat v5.5 Server Click Next
  4. Under Tomcat installation directory: Browse to the place where you unzipped the Tomcat installation
  5. Under JRE: Make sure jre1.5.x is selected, you may need to add the jre if a different one is installed on your computer. Click Next
  6. Choose the project you created from Available projects to Configured projects Click Finish
  7. Open the Server View, if it’s not displayed already – Window –> Show View–> Other–> Choose Servers under Server
  8. Save the Perspective so that the Servers View will also be displayed
  9. The server you just created will appear in the Servers View
  10. Right Click the server and choose Move to Workspace
  11. Double click the Server and the Server Overview will be opened.
  12. Change the Server Name to something meaningful like YourProjectName Server, Save the configuration
  13. Close the editor and it will ask you if you want to rename the diretory to match the server name, click yes
  14. Open the server.xml
  15. Change the appBase attribute of the Host node to contain the absolute path to your workspace directory ex. <Host appBase=”d:\web” autoDeploy=”true” name=”localhost” unpackWARs=”false” xmlNamespaceAware=”false” xmlValidation=”false”>
  16. Change the port attribute of the Connector node to 80 and the redirectPort attribute to 443
  17. Change the docBase attribute of the Context Node to contain the absolute path to your WebContent folder ex. <Context docBase=”d:\web\yourprojectname\WebContent” path=”/” reloadable=”true” source=”org.eclipse.jst.j2ee.server:forensicsalvage”/>

You should be able to start the server up from the Server View and view you application and make live changes to your jsp’s, which should only require a refresh now.

Comments