Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 views
in Technique[技术] by (71.8m points)

java - 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:

  • core is a class library and depends on, lets say, a.jar.
  • web is the web application and depends on core.

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...