Installing Eclipse and Tomcat Together on Windows
By: Troy Campano
(2004-10-13)
Filed under Articles > Programming > Java

Introduction
This article will describe how to install Apache Tomcat, Eclipse, the sysdeo plugin which hooks Eclipse into Tomcat, the sysdeo plugin patch, and an example on how to write a Java Server Page within Eclipse. In these examples I will using Apache Tomcat 4.1.29, Eclipse 3.0.1, and Java 1.4.2. I have tested this on Windows XP and Windows 2000 but I'd imagine this would also work without problems on other versions of Windows that support these versions of Apache Tomcat and Eclipse.

Getting and Installing the Needed Files
Getting Java
The first step is to download the files necessary for installation. First, if you don't have Java 1.4 already installed you will need to download it. For this specific example I used the Java 2 SDK 1.4.2_04. I've heard that currently there are issues using Java 1.5 (now called Java 5) with Eclipse 3.0.1 so I'd recommend sticking with Java 1.4.2. You can download Java 2 SDK 1.4 at http://java.sun.com/products/archive/. Once downloaded, you can easily install it using the installer. I'd recommended keeping the defaults and installing it right off the C: drive. For my installation, Java was installed at C:\j2sdk1.4.2_04\.

Getting and installing Eclipse
Next you'll want to download Eclipse. You should be able to download Eclipse from http://eclipse.org/downloads/index.php. Again, I'm using Eclipse 3.0.1. I haven't tested that the tomcat plugin works with other versions so if you can you'll want to stick with Eclipse 3.0.1. The download file comes in a ZIP file format. Once downloaded you'll want to extract it. In my case, I've extracted the files to c:\eclipse\. Once extracted, my eclipse program is at c:\eclipse\eclipse.exe. If you want, you can double click the eclipse binary and eclipse should start up. If Eclipse starts up without any trouble then you can close so that we can add plugins to it later. (note: If you have Oracle installed and get an error when starting eclipse please see the Common Problems section below)

Getting Tomcat
Next you'll want to download your Apache Tomcat server. Apache Tomcat is a servlet container. It allows you to run your JSP and Servlet web pages. At the time of this writing, you could download Apache Tomcat from here: http://archive.apache.org/dist/jakarta/tomcat-4/v4.1.29/bin/jakarta-tomcat-4.1.29.zip. If you can't download it from there, you may want to dig through the archives and look for the jakarta-tomcat-4.1.29.zip file. Once you have the jakarta-tomcat-4.1.29.zip file downloaded, extract it to c:\tomcat\ so that you have a directory structure set up like this:

  c:\tomcat\bin\
           \common\
           \conf\
           \logs\
           \server\
           \shared\
           \temp\
           \webapps\
           \work\
  

Getting and installing the Sysdeo Plugin and Patch
A company called Sysdeo created a plugin for Eclipse that allows you to start, stop, restart, configure Tomcat, create WAR files, etc. all within the Eclipse IDE. What you will need to do is download the plugin and then hook it into Eclipse. For the plugin to work properly with Tomcat you'll also need to download a patch for the Tomcat server. This will allow you to compile your servlets from within Eclipse. First, you'll want to download the plugin which can be found here for Eclipse 3.0.1: http://www.sysdeo.com/eclipse/tomcatPluginV3.zip. Next you'll also want to download the patch from here: http://www.sysdeo.com/eclipse/jasperDebugPatchV4.1.24.zip. The patch says it's for Tomcat 4.1.24 but it works with Tomcat 4.1.29 as well. Once you have both files, extract the patch to wherever you like. You should now have a folder called com.sysdeo.eclipse.tomcat_3.0.0. You can to copy that entire folder into the eclipse plugins directory located here on your computer if you've used the directory layout from above: c:\eclipse\plugins\. Once copied, the full path to the plugin should be c:\eclipse\plugins\com.sysdeo.eclipse.tomcat_3.0.0\.That's it, the plugin will be read by eclipse when eclipse is started.

Configuring the Sysdeo Plugin with Eclipse
The next step is to configure eclipse with the sysdeo plugin so that you can properly run tomcat with eclipse. First, you'll want to start up eclipse by double clicking the eclipse.exe file at c:\eclipse\eclipse.exe. After a few moments eclipse should start up and you should see three tomcat icons towards the top left of eclipse. This means that eclipse loaded the sysdeo plugin. it should look similar to this:

Now we need to tell Eclipse where to find Tomcat so that it can work with it. Under the 'Window' menu in eclipse, go to 'Preferences'. A window should open up and you should see an option for 'Tomcat' on the left. Click the Tomcat option and you should be able to enter your Tomcat version and the location of Tomcat. It should look similar to below:

...once you're done modifying your options on this screen click the 'Apply' button. Next click the plus sign next to the Tomcat option on the left to configure the next set up option. You should see the options: Advanced, JVM Settings, Source Path, and Tomcat Manager App. You only need to configure the options under JVM Settings. Click JVM Settings and you should see three white boxes where you can add some JAR files to your classpath. You need to add tools.jar to the classpath and rt.jar to your boot classpath. Both of these JAR files are found within your Java home directory. You should set up your options to look somewhat similar to this:

Once that is done, click Apply and then OK. Eclipse should now know where to find tomcat and the needed java libraries.

Patching Tomcat to Work with the Sysdeo Plugin
The next step will require the Sysdeo patch you downloaded called jasperDebugPatchV4.1.24.zip. Extract this zip file and you should have a directory called org and a read me file. You can read the README file but basically what you want to do is copy the org directory into /common/classes/ so that if you have Tomcat installed at c:\tomcat\ it would be placed like this: c:\tomcat\common\classes\org\. Once you've done that tomcat should be ready to go.

Starting Tomcat and Writing Some Code
You should be able to start Tomcat by either clicking the Tomcat icon in eclipse or by going to the 'Tomcat' menu in eclipse and then clicking 'Start Tomcat'. Once you click the icon, a bunch of messages should be outputted to the eclipse console. You'll want to pay close attention to the messages in the console to make sure you don't get any java exceptions but after a minute tomcat should be up and running now. You should be able to view the Tomcat Welcome Page on your computer from this address: http://localhost:8080/. If all goes well you should see a web page that looks similar to this:

Next you can write your own JSP page to make sure everything is working correctly. The first step is to set up a new Tomcat Project. To do this, go to eclipse and from the File menu click New and then Project like this:

A new window will pop up and under the Java folder, you'll want to select Tomcat Project and then click Next like so:

On this next screen you will be able to name the project and tell eclipse where the project will be located on your hard drive. We will use an existing web application called ROOT within Tomcat for this example. In the 'Project Name' text box type in the word ROOT in uppercase. Under 'Project Contents' uncheck the 'Use default' checkbox. Next click the browse button and browse to c:\tomcat\webapps\ROOT like so:

...then click Next. On this next screen the only thing you want to change is the checkbox that says 'Can update server.xml file'. You want to uncheck this box. I've found that this plugin can reak havok with my server.xml when I start to get into more complicated web app resource definitions like when I use connection pooling. Your window should now look like this:

...and now click Finish. You should now have a project called ROOT that looks like this in eclipse:

Right click the ROOT project and go to New -> File like this:

Call the file test.jsp and click the Finish button. You should see in the file navigator on the left that the file test.jsp was added to your project. Double click the test.jsp file and it should open up in eclipse for editing. Copy the following code into test.jsp:

<html>
<head>
<title>My JSP Hello World</title>
</head>
<body>
Hello World, this is HTML.<br/><br/>
<%
out.println("Hello World, this is JSP");
%>
</body>
</html>

...now save the file. If you then bring up your brower to http://localhost:8080/test.jsp you should see a screen like this:

You now have Eclipse configured and running with Apache Tomcat!

Some Common Problems
Oracle and Eclipse Don't Play Nice
If you have installed Oracle on your computer, Oracle will have a tendency to overwrite the link for your system JVM to use the JVM in Oracle instead of your own Java 1.4. If you start eclipse and a pop says An Error Has Occurred and then tells you to check the log file which says something like:

!SESSION Oct 13, 2004 22:15:02.02 ----------------------------------------------
eclipse.buildId=I200406251208
java.version=1.3.1_01
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US

!ENTRY org.eclipse.osgi Oct 13, 2004 22:15:02.02
!MESSAGE Error registering XML parser services.
!STACK 0
java.lang.ClassNotFoundException: javax.xml.parsers.SAXParserFactory
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	...

...then it sounds like you have the problem too. One way to fix this is to pass the eclipse.exe program the 'vm' parameter to tell eclipse to use the JVM that you want it to. To do this open a dos command prompt and type in:

C:\eclipse\eclipse.exe -vm c:\j2sdk1.4.2_04\bin\javaw.exe

...making sure to replace the location of your eclipse.exe and javaw.exe files to wherever they are on your computer. You can set up a shortcut icon in Windows so you don't have to type this each time.

Starting Tomcat in Eclipse and Getting the 'Address already in use' error
If you start Tomcat in Eclipse you may get this error in the console:

SEVERE: Error initializing endpoint
java.net.BindException: Address already in use: JVM_Bind:8080
	at org.apache.tomcat.util.net.PoolTcpEndpoint.initEndpoint(PoolTcpEndpoint.java:302)
	at org.apache.coyote.http11.Http11Protocol.init(Http11Protocol.java:184)
	at org.apache.coyote.tomcat4.CoyoteConnector.initialize(CoyoteConnector.java:1229)
	at org.apache.catalina.core.StandardService.initialize(StandardService.java:579)
	...

This means that something else is already running on port 8080, so Tomcat can't start up and run on this port. So you have two options: shut down what is running on port 8080 before you try to start running Tomcat or modify your server.xml file in

In Summary
Here's a brief summary on how to configure Tomcat with Eclipse:

  • Download the needed files
  • Unpack Tomcat and Eclipse
  • Unpack the Sysdeo plugin into the Eclipse plugins directory
  • Unpack the Sysdeo plugin patch folder into /common/classes/
  • Start Eclipse
  • Go to Window -> Preferences and set Tomcat Home, Tomcat Base, tools.jar, and rt.jar
  • Create a project and start writing your JSP!

If you have any questions or comments, please post them below. Good Luck!

~ Troy Campano ~


Reader's Comments - Add Comment


Find some of this content useful? Please consider a donation. Any donation is appreciated.