Forums Register Login

Setting up project dependencies in eclipse

+Pie Number of slices to send: Send
Hello,

I have a java project (calling it ProjectA) that contain all my
hibernate mappings xml files inside classpath along with model
classes. I then have second web project(ProjectB) that uses those. I have successfuly added ProjectA as dependecies into ProjectB's under "Java Build Path" settings, and compile will see the depended classes.

But I run into problem when starting up ProjectB as webapp in a eclipse's tomcat server. It complains missing and not able to load hibernate mapping resource files from classpath. Any one done this because who can give me some point on how to setup eclipse with these projects?

Thanks for helping.
+Pie Number of slices to send: Send
I think I understood what you're saying. The thing to keep in mind is that in Tomcat, each webapp has its own classpath. What Eclipse thinks of as the classpath may not be the same thing - especially if you're trying to draw from multiple projects.

For a simple WAR-type webapp, the only classes Tomcat will see are those in the webapp's WEB-INF/classes and WEB-INF/libs (unless you start adding custom classloaders). And if you have multiple webapps, each webapp will have its own classpath configuration. The webapps can also draw on classes defined at the Tomcat global level, but you should leave that option for truly global classes - like logging libraries and maybe JDBC driver JARs. I personally don't recommend putting framework libraries such as Hibernate in the Tomcat shared library directories. At best, it makes portability and version independence difficult, and in worse cases, may cause unpredictable results due to multi-threading and shared resource conflicts.

The documentation for how Tomcat's classpath hierarchy works is graphed out in detail at the jakarta.apache.org/tomcat website.

Normally what you'd do in terms of a 2-project Tomcat solution would either be a case where you have 2 webapps - and the safest way for them to talk is usually HTTP requests between them. Or you might define a JAR as an Eclipse project and include the constructed JAR into a webapp project. However, if you do that, what you actually have to do is make the JAR project build a JARfile and then have a copy of that JARfile copied into the webapp project's WEB-INF/lib directory. You'd set the Eclipse project dependencies to tell Eclipse that the JAR has to be built before the webapp.
+Pie Number of slices to send: Send
We are using the Development-Webapp Classloader together with the sysdeo plugin, as outlined at http://www.eclipsetotale.com/tomcatPlugin/readmeDevLoader.html (I think the comment on the devloader only being available for Tomcat 4 is outdated). That way we we can run a webapp consisting of dozens of Eclipse projects directly from inside Eclipse - no need for the creation of any jars or wars. Works great.
+Pie Number of slices to send: Send
Well, I usually only actually create WAR files when I'm ready to ship a deployable, but I build into an exploded WAR (typically a directory named build/webapp). I use sysdeo. And one of the reasons I tend to prefer Eclipse over IntelliJ is because I not uncommonly am running multiple intercommunicating webapps (and other things) concurrently within the Eclipse debugging environment.

Or have you managed to bypass the WAR structure altogether. And if so, how?
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1814 times.
Similar Threads
How to Compile source code from a different Java project using Maven
Problem using Eclipse 3.4
Eclipse: different compiler per project
Eclipse WAR file errors
Help creating replicated Netbeans project?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:57:28.