<import resource="classpath:uk/co/bigsoft/beans.xml"/>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:
class org.springframework.web.context.ContextLoaderListener 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 existThis 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
Comment from: Broc [Visitor]
This is precisely what I am trying to accomplish. I am actively developing two java projects that I would normally compile into jar files when I go to production. But I simply want Tomcat to see these extra projects in its classpath while I develop in eclipse.
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?
Comment from: [Member]
I thought I had cracked it when I found a clue to the above solution. However in my haste to blog I had forgotten that I have previously copied the other project’s class files into the correct place for another test! When I tried later to reproduce the solution I couldn’t get it to work. 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!
Comment from: [Member]
Just in case you and I are the only people suffering from this, I’ve added a bug at Eclipse for this:
Running Tomcat in debug mode fails to deploy properly with multiple projects: https://bugs.eclipse.org/bugs/show_bug.cgi?id=259938
Comment from: Prashanth Menon [Visitor]
Form is loading...