7

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!

4

4 回答 4

11

好吧,与此同时,我自己找到了答案。

对于那些将来阅读本文的人,我将使用我在原始消息中介绍的语义逐步解释:

首先,打开核心项目的属性页面并导航到“Java Build Path”设置的“Libraries”选项卡:

在此处输入图像描述

确保通过“添加 JAR ...”添加您的类库a.jar,您的核心项目依赖于此。然后,转到“订购和导出”选项卡并激活刚刚添加a.jar的导出。

在此处输入图像描述

然后转到“部署程序集”设置并在a.jar此处添加,首先单击“添加...”,然后单击“Java 构建路径条目”,最后选择a.jar. 确保输入“../”作为部署路径a.jar

在此处输入图像描述

现在你已经完成了你的核心项目。现在为您的Web项目打开“Java 构建路径”设置的“项目”页面,并通过单击“添加...”添加您的核心项目:

在此处输入图像描述

最后,导航到“部署程序集”设置页面,按“添加...”,然后选择“项目”并在下一个屏幕上选择您的核心项目:

在此处输入图像描述

你完成了。无需将核心依赖项添加到Web项目中。

于 2012-10-03T22:18:20.470 回答
0

我建议使用Maven,它会自动jar为您编译文件并且也Eclipse可以Maven很好地工作。

于 2012-06-19T07:24:15.873 回答
0

据我所知,日食不适合你。项目依赖项用于编译时。跨项目的运行时依赖项应由您处理。您可以使用一种技巧来创建用户库。转到首选项 -> Java -> 构建路径 -> 用户库。创建一个新的用户库。添加您的“核心”项目所依赖的所有 jar。将其作为依赖项添加到“核心”和“网络”项目。为此,请右键单击项目 -> 构建路径 -> 配置构建路径 -> 库选项卡 -> 添加库...

希望这可以帮助

于 2012-06-19T07:11:16.393 回答
0

如果您有 Gradle-Project,请确保您的子项目的 build.gradle 中有“eclipse-wtp”插件。

于 2020-12-11T12:25:31.967 回答