[英]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.我在提供使用 Tomcat 6 和 Eclipse 部署动态 Web 应用程序时使用的一些第三方库(JAR 文件)时遇到问题。
Please note that I -do know- how to do this in a setup, where the web application project -directly- depends on those JARs.请注意,我知道如何在设置中执行此操作,其中 Web 应用程序项目直接依赖于这些 JAR。
However, in my setup, I have two Eclipse projects:但是,在我的设置中,我有两个 Eclipse 项目:
a.jar
. a.jar
。 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.在web的项目设置中,在Deployment Assembly类别中,我添加了core ,因此 Eclipse(或 Tomcat - 我不太确定这里的负责人是谁)将
core.jar
放入我的 web 应用程序的libs
目录中.
The problem is: When I try out the web application, a NoClassDefFoundError
is thrown when core accesses classes from a.jar
.问题是:当我尝试 Web 应用程序时,当核心从
a.jar
访问类时抛出NoClassDefFoundError
。 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.我不认为将
a.jar
放入我的 web 应用程序的部署程序集设置页面是正确的解决方案,因为它应该与web项目无关,核心项目依赖什么。
Basically, I am looking for a way to configure Eclipse (Tomcat?) to 'embed' the dependencies of core into core.jar
.基本上,我正在寻找一种方法来配置 Eclipse(Tomcat?)以将core的依赖项“嵌入”到
core.jar
。 The problem about this is, that core.jar
is generated automatically, when I deploy my web project.关于这个的问题是,
core.jar
是在我部署我的web项目时自动生成的。
Help is very appreciated.非常感谢帮助。 Thanks in advance!
提前致谢!
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:首先,打开核心项目的属性页面并导航到“Java 构建路径”设置的“库”选项卡:
Make sure to add your class library a.jar
, your core project depends on, via 'Add JARs...'.确保添加您的类库
a.jar
,您的核心项目依赖于,通过“添加 JAR...”。 Then, go ahead to the 'Order and Export' tab and activate the just added a.jar
for exporting.然后,转到“订购和导出”选项卡并激活刚刚添加的
a.jar
以进行导出。
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
.然后进入“部署大会”的设置,也可以添加
a.jar
在这里,首先单击“添加...”,然后在“Java构建路径条目”,最后选择a.jar
。 Make sure to enter '../' as the deploy path for a.jar
:确保输入 '../' 作为
a.jar
的部署路径:
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...':
现在打开Web项目的“Java 构建路径”设置的“项目”页面,并通过单击“添加...”添加核心项目:
Finally, navigate to the 'Deployment Assembly' settings page, press 'Add...', then take 'Project' and select your core project on the next screen:最后,导航到“部署程序集”设置页面,按“添加...”,然后选择“项目”并在下一个屏幕上选择您的核心项目:
You're done.你完成了。 No need to add your core dependencies to your web project.
无需将您的核心依赖项添加到您的Web项目中。
As far as I know eclipse doesn't do it for you.据我所知 eclipse 不适合你。 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.
转到首选项 -> Java -> 构建路径 -> 用户库。 Create a new user library.
创建一个新的用户库。 Add all the jars that your 'core' project depends on.
添加您的“核心”项目所依赖的所有 jar。 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希望这可以帮助
我建议使用Maven ,它会自动为您编译jar
文件, Eclipse
可以很好地与Maven
配合使用。
如果您有 Gradle 项目,请确保在子项目的 build.gradle 中有“eclipse-wtp”插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.