Eclipse调试时间类路径问题:如何将依赖项目的输出包含到Web项目的运行时类路径中? [英] Eclipse debug-time classpath problem: How do you include a dependent project's output into a web project's runtime classpath?

查看:129
本文介绍了Eclipse调试时间类路径问题:如何将依赖项目的输出包含到Web项目的运行时类路径中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我开始使用从eclipse正确构建和调试的Web服务项目(只是一个动态Web项目)。我们已经把一大堆常见的代码放入我们想要放入共享库中,所以现在这些类将进入一个单独的jar项目,web项目引用。

So I started with a web services project (just a dynamic web project) that builds and debugs correctly from eclipse. We've pulled a chunk of common code out that we want to put into a shared library so now those classes are going into a separate jar project that the web project references.

在Web项目中,我做了Project-> Properties-> Java Build Path-> Projects->添加并添加了jar项目。这正确地解决了所有的编译时类路径问题,一切都构建得很好。但是在运行时,当tomcat服务器启动时,Spring尝试注入jar文件中包含的一些类,并获得一个NoClassDefFoundError。

On the web project, I did Project->Properties->Java Build Path->Projects->Add and added the jar project. And this correctly solved all the compile-time classpath problems and everything builds fine. But at runtime, when the tomcat server fires up, spring attempts to inject some of the classes contained in the jar file and I get a NoClassDefFoundError.

我的.class和属性文件和我的META-INF目录的内容显示在./build目录中,但是我的WEB-INF / lib目录似乎被原位引用,并且jar依赖关系不会被复制到它以显示作为Web应用程序库的一部分。

My .class and properties files and the contents of my META-INF directory are showing up in the ./build directory, but my WEB-INF/lib directory seems to be referenced in-place, and the jar dependency doesn't get copied in to it to show up as part of the Web App Library.

什么是魔术咒语告诉eclipse其他jar项目需要在运行时可用于tomcat?从我们的蚂蚁构建脚本开始,我们首先将另一个项目构建到WEB-INF / lib中,一切都可以正常工作,但不适用于eclipse调试。

What is the magical incantation to tell eclipse that the other jar project needs to be available to tomcat at runtime? From our ant build script, we first just build the other project into WEB-INF/lib and everything works fine, but not for eclipse debugging.

推荐答案

Java EE模块依赖将解决这个问题。
您已经完成了将常用类提取到自己的项目可能中的任务,因为其他项目依赖于这些类。无论哪种方式,您都必须确保这是一个实用程序项目(在项目向导中的Java EE下显示),而不仅仅是一个普通的Java项目。
完成之后,您可以继续按照您的想法将实用程序项目添加到构建路径(编译时路径)。

Java EE module dependencies would solve this problem. You have already done the task of extracting your common classes into its own project, possibly because other projects depend on these classes. Either way, you'll have to ensure that this is a Utility project (appears under Java EE in the project wizards), and not just a plain Java project. One that is done, you can proceed to add the Utility project to your build path (compile-time path) as you have figured out.

附加(最终)步骤是在您的Dynamic Web项目和共享库之间建立Java EE模块依赖关系,这将导致实用程序的类在部署期间甚至在导出WAR期间放置在WEB-INF \lib中。为此,请访问动态Web项目的属性,并浏览到Java EE模块依赖关系。确保您的实用程序项目被选中。重新部署/发布您的应用程序,您应该很好去。

The additional (final) step is to establish a Java EE module dependency between your Dynamic Web project and the shared library, which causes the utility's classes to be placed in WEB-INF\lib during deployment, and even during export of the WAR. To do so, visit the dynamic web project's properties, and browse to the Java EE module dependencies. Ensure that your utility project is selected here. Redeploy/publish your application and you should be good to go.

这篇关于Eclipse调试时间类路径问题:如何将依赖项目的输出包含到Web项目的运行时类路径中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆