| « Forwarding Plesk mail from a virtual email address to multiple recipients | rm: Argument list too long » |
Configuring Eclipse to use Tomcat and the Spring Framework
There never seems to be enough documentation on how to create Spring Framework enabled projects in Eclipse. Spring is widely used for web applications so you need to know how to integrate Tomcat and Eclipse as well - so there is even less documentation! There follows below a step-by-step set of instructions to do just that.
I am not going to describe how to install the Java Runtime environment. If you need help with that, then maybe web services is not the career you should be focusing on ;) Needless to say it is a requirement of all the following technologies.
Installation
Windows is (not) funny about spaces in directory names so all the installations will be located under c:\java instead of c:\Program Files. You’ll save yourselves an enormous headache trying to figure out why Windows is not interpreting the command lines properly if you just remove the cause of the problem. Bloody Bill!
- Download Eclipse IDE for Java EE Developers 3.4 Ganymede from the downloads section of the Eclipse web site.
- Extract the
eclipse-jee-ganymede-win32.zipintoc:\Java\eclipse. - Create a desktop shortcut to the Eclipse executable, for easy launching.
- Download Tomcat 6.x from the downloads section of the Tomcat web site. You will need to get the base (Core) pack and not the windows installer pack. The windows installer pack does not include some of the command-line scripts for launching Tomcat.
- Extract the
apache-tomcat-6.0.18.zipintoc:\java\apache-tomcat-6.0.18then rename it toc:\java\tomcat. - Launch Eclipse.
- On a new install of Eclipse it asks you where you want to put your workspace. We are going to place it in
c:\java\workspacebecause the spaces issue will be a problem if it goes intoc:\Documents and Settings\David Newcomb\workspace. - Next we are going to install our Spring IDE plugin, full instructions on how to do this are on my blog page entitled Eclipse 3.4 Ganymede and Spring IDE 2.0.6.
- After installation it says It is strongly recommended you restart your system for the changes to take effect. .. Restart now?, when it says system it means the eclipse workbench and not your whole computer, so click Yes.
Configure Tomcat inside Eclipse
Next we need to tell Eclipse about which Tomcat we are using and set up the integration.
- From the menu bar select Window->Preferences.
- The Preferences window will open. Expand Server.
- Highlight Runtime Environment. This is the place where you can tell Eclipse about where you put your Tomcat installation.
- Click Add.
- Expand Apache and select Apache Tomcat v6.0.
- Check the Create a new local server check box to create a new server in the Servers view.
- Click Next.
- Leave the Name of the server set to Apache Tomcat v6.0.
- Eclipse gives the option to download a version of Tomcat but it usually does not have the latest version (which is why we downloaded it separately). Click Browse and navigate to
c:\java\tomcat and click Ok. - Leave the JRE drop down set to Workbench default JRE.
- Click Finish.
- You are taken back to the Server Runtime Environments preference page so click Ok.
- A new project will have been created and if you go into the Servers view (in the bottom set of tabs), you will see a new server Apache Tomcat v6.0 at localhost.
Create project
There are several different types of project in Eclipse and we need the one that will allow us to integrate all the things we need.
- Select File->New->Dynamic Web Project
- Enter a Project name. Although you can have spaces, in my opinion, it’s best not to put any in. The project name becomes the directory name and for the same reason as above it’s a pain if there are spaces.
- The Target Runtime should already be set to Apache Tomcat v6.0.
- Also keep the Configuration set to Default Configuration for Apache Tomcat v6.0.
- Click Finish.
- In the Project Explorer, right click on the new project and select Spring Tools->Add Spring Project Nature.
Spring Web project and Tomcat project association
We must now associate the project with Tomcat.
- Make sure the Servers view is visible (in the bottom set of tabs). Highlight your new Spring Web project and drag it on to the Tomcat v6.0 Server at localhost entry in the Servers tab.
- We want to use the Tomcat server when we use our new project, so we can set the Server project to be a dependency of our new project. This will mean that when we open our project the Server project will open automatically.
- Right click on our project and select Properties.
- Select the Project References option and check the Servers project.
- Click Ok.
26 comments
The JEE version of Eclipse comes with support for several versions of application servlet container and application server e.g. JBoss, WebSphere, JOnAS, Oracle OC4J and Apache Tomcat.
I found there was no need to load any "extra" plugins.
You still need installed copies of those applications but if you follow my instructions, just substitute Tomcat with your application.
Would appreciate if any one can give me some sample projects ref of spring webservice. thanks in advance!!
i have to work struts2.0 with tomcat6.0 in Eclipse Ganymede..
i configured tomcat6.0 like u said here... but i couldnt get the output when i tried http://localhost:8080/ in the browser... it should show tomcat home page na..
since its not worked i havent try struts2.0 .. can u please tell me the solution for this
Try asking in the Spring Forum.
I've been through all the posts in this forum. I've been trying to run my Dynamic Web Project from Eclipse Ganymede itself. I'm planning to use the run time debugging feature so that it becomes easier to debug my Spring webservice. As mentioned by Juni, even I'm not able to get my tomcat working. The server is in running condition but it fails and gives a 404 HTTP not found error if I hit any URL on localhost:8080. Everything works fine if I deploy my project using an Ant script and run my server separately. But in that case, I'm not able to debug the same. A possible reason for such a problem is that Eclipse is trying to run tomcat as a separate instance and takes the webapps from .metadata/.plugins/org.eclipse.wst.server.core/tmp0 in its workspace directory.
It has been mentioned on some other forums that unchecking on "Run directly from workspace" option in the Server Overview shall make Eclipse work in CATALINA_HOME/webapps instead of the workspace directory. However, I'm not able to find such an option in Ganymede. Also, the Server Locations have been disabled on its Overview page due to some reason. There's a radio button that would enable me to alter the path but changing that option is not allowed. Is there a way to fix this?
I'm not able to get my Apache Tomcat 6 and its web applications running from within Eclipse.
.metadata/.plugins/org.eclipse.wst.server.core/tmp0 before tomcat is launched from inside Eclipse.Eclipse runs tomcat by explicitly setting
catalina.base, catalina.home, wtp.deploy and java.endorsed.dirs to point to your .metadata directories.In order to do the publish you must associate the dynamic web project with the Tomcat server in the Server view.
I'm ready to downgrade if thats exactly what it takes to run Tomcat successfully. :(
Do you visit any informative spring or JSF websites you could share as well?
Thumbs up
thanks in Advance
:)