|« Setup and install of multiuser phpMyID (OpenID) under Plesk||cvc-id.1: There is no ID/IDREF binding for IDREF 'transactionManager' »|
Adding multiple Eclipse projects to Tomcat's classpathNovember 12th, 2008
In order to avoid full file-system paths in a Tomcat configuration, you make all the file references point to elements on the classpath. The classpath is an environment variable which is set outside of Tomcat, and is the search path that the class loader uses in order to find classes.
When importing another bean definition file you would be far better off using something along the lines of the following, instead of a
Under Eclipse (3.4 Ganymede (but I’m sure this applies to all versions of Eclipse)) you can link projects together and create project dependencies. Creating a dependency means that when you open a project, it will open the projects it depends on. Also, when you run the project it incorporates the classpath of the dependant projects into its own classpath.
If you do this and run Tomcat you will get an error similar to:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:uk/co/bigsoft/proj/dino.live.xml]
Offending resource: ServletContext resource [/WEB-INF/sitemanager-webapp-config.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [uk/co/bigsoft/proj/dino.live.xml]; nested exception is java.io.FileNotFoundException: class path resource [uk/co/bigsoft/proj/dino.live.xml] cannot be opened because it does not exist
This problem occurs because Tomcat is running as a separate application with its own environment - an environment that does not include classpath links to your other Eclipse projects (even though you have linked them together in Eclipse).
There follows a step-by-step guide to adding multiple Eclipse projects to Tomcat classpath. This follows on from the Configuring Eclipse to use Tomcat and the Spring Framework article I wrote earlier.
- After attaching the project to the Tomcat server, double click the Tomcat v6.0 Server at localhost to popup the Tomcat server configuration window.
- Click General Information->Open launch configuration
- Select Classpath tab
- Highlight User Entries (buttons will become enabled)
- Click Add projects… button
- Check the boxes of the projects you want to include.
- Click ok….ok….etc
Your above instructions seem to be the right solution, however, when I publish (or even do "Clean...") none of my classes are ever copied out to the tomcat directory. (e.g. to directory .metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MyWebApp\WEB-INF\classes)
I am using eclipse ganymede 3.4.1.
Any other tricks or configs I am missing?
I left this blog up to provide another piece of the puzzle, in case someone else can find out how to do it.
Although there is a light, I was recently talking to Mark Thomas (lead contributor to the Apache Tomcat project) [sorry about the shameless name dropping] and showed him. After a lot of fiddling he agreed that this was the solution, but there was a bug in Eclipse and the class files should be copying across. We were on a tight deadline and needed to get something working and found that the easiest thing to do was keep the projects separate and jar up the other project's classes and copy them into the WEB_INF/lib. Not an ideal solution, but at least you can run it in the debugger, hot recompiles are a bit flaky but it does the job.
So I think the relevant people have been alerted, but if anyone else has any suggestions on what the current work-around is then please, please, pretty please tell us how.
So fingers crossed for the next release!
Running Tomcat in debug mode fails to deploy properly with multiple projects: