kostrykin
kostrykin

Reputation: 4292

Eclipse Web-App Deployment with Tomcat: Providing multiple projects' dependencies?

I have a problem providing some third party librarys (JAR-files) I am using when deploying my dynamic web application with Tomcat 6 and Eclipse.

Please note that I -do know- how to do this in a setup, where the web application project -directly- depends on those JARs.

However, in my setup, I have two Eclipse projects:

In the project settings of web, in the Deployment Assembly category, I have added core, so Eclipse (or Tomcat - I'm not quite sure who the responsible actor here is) is putting core.jar into the libs directory of my web application.

The problem is: When I try out the web application, a NoClassDefFoundError is thrown when core accesses classes from a.jar. What am I supposed to do about this? I don't think that putting a.jar into the Deployment Assembly settings page of my web application is the right solution, since it should be of no relevance to the web project, what the core project depends on.

Basically, I am looking for a way to configure Eclipse (Tomcat?) to 'embed' the dependencies of core into core.jar. The problem about this is, that core.jar is generated automatically, when I deploy my web project.

Help is very appreciated. Thanks in advance!

Upvotes: 7

Views: 6653

Answers (4)

Nakor74
Nakor74

Reputation: 1

If you have a Gradle-Project make sure, you have the "eclipse-wtp" Plugin in your build.gradle's of the Sub-Projects.

Upvotes: 0

kostrykin
kostrykin

Reputation: 4292

Well, I've found the answer on my own meanwhile.

For those reading this in the future I will explain step by step, using the semantics I introduced in my original message:

First, open the properties page of your core project and navigate to the 'Libraries' tab of the 'Java Build Path' settings:

enter image description here

Make sure to add your class library a.jar, your core project depends on, via 'Add JARs...'. Then, go ahead to the 'Order and Export' tab and activate the just added a.jar for exporting.

enter image description here

Then go to the 'Deployment Assembly' settings and also add a.jar here by first clicking on 'Add...', then on 'Java Build Path Entries' and finally selecting a.jar. Make sure to enter '../' as the deploy path for a.jar:

enter image description here

Now you are done with your core project. Now open the 'Projects' page of the 'Java Build Path' settings for your web project and add your core project by clicking on 'Add...':

enter image description here

Finally, navigate to the 'Deployment Assembly' settings page, press 'Add...', then take 'Project' and select your core project on the next screen:

enter image description here

You're done. No need to add your core dependencies to your web project.

Upvotes: 11

adranale
adranale

Reputation: 2874

I suggest using Maven which will automatically compiles the jar files for you and Eclipse works with Maven very well too.

Upvotes: 0

Ravi
Ravi

Reputation: 553

As far as I know eclipse doesn't do it for you. Project dependencies are for compile time. Runtime dependencies that span across projects should be handled by you. One trick you can use to create user libraries. Go to preferences -> Java -> Build Path -> User libraries. Create a new user library. Add all the jars that your 'core' project depends on. Add it as a dependency to both 'core' and 'web' projects. To do that,, right click on project -> Build Path -> Configure build path -> Libraries tab -> Add Library...

Hope this helps

Upvotes: 0

Related Questions