且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Eclipse调试时间类路径问题:如何将依赖项目的输出包含到Web项目的运行时类路径中?

更新时间:2022-01-25 01:37:19

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.