Deploying Eclipse Web Applications with Tomcat: Providing Multiple Project Dependencies?

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

Note that I -do the know-how to do this in setup, where the web application project - directly - depends on these JARs.

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

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

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

Problem: when I try to execute a web application, NoClassDefFoundError is raised when core accesses the classes from a.jar . What should I do? I don’t think that placing a.jar on the deployment assembly settings page of my web application is the right solution, since it should not have any relation to the web project, which means depends on.

Basically, I'm looking for a way to configure Eclipse (Tomcat?) To "embed" kernel dependencies in core.jar . The problem is that core.jar generated automatically when I deploy the web project.

Help is much appreciated. Thanks in advance!

+6
source share
3 answers

Well, I found the answer myself in the meantime.

For those who read this in the future, I will explain step by step using the semantics introduced in my original post :

First, open the core project properties page and go to the "Libraries" tab of the "Java Build Path" parameters:

enter image description here

Be sure to add your a.jar class a.jar , your core project depends on through "Add JARs ...". Then go to the Order and Export tab and activate the just added a.jar for export.

enter image description here

Then go to the Deploy Deployment settings, and then add a.jar here, first clicking Add ..., then Java Build Path Entries, and finally selecting a.jar . Be sure to enter "../" as the deployment path for a.jar :

enter image description here

Now you have finished the core project. Now open the Projects page of the Java Build Path path for the web project and add the core project by clicking Add ...:

enter image description here

Finally, go to the "Install Deployment" settings page, click "Add ...", then take "Project" and select the core project on the following screen:

enter image description here

You are done. No need to add your dependent core to your web project.

+8
source

As far as I know, an eclipse does not do this for you. Project dependencies depend on compilation time. The runtime dependencies that span all projects must be handled by you. One trick you can use to create custom libraries. Go to Settings -> Java -> Build Path -> User Libraries. Create a new custom library. Add all the banks on which your "main" project depends. Add it to your core and web projects. To do this, right-click on the project β†’ Build Path β†’ Configure Build Path β†’ Libraries tab β†’ Add Library ...

Hope this helps

0
source

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

0
source

Source: https://habr.com/ru/post/918347/


All Articles