从 Eclipse 导出后,WAR-File 中缺少一些必要的库 - 为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3529690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:01:43  来源:igfitidea点击:

Some necessary libraries are missing in WAR-File after export from Eclipse - why?

javaeclipseexportjavascriptwar

提问by Stephan

I took over a project of a college which contains some web services and by exporting the project as WAR-file some libraries are contained in the file (e.g. Axis2) and some aren't (hibernate, JDBC driver). Also a jar which is added to the class path has not been exported. All libraries are located in folders on the hard drive which means that they are not in located somewhere in the eclipse folder. If I open the WAR-file after export with WinRAR and add the libraries manually to the file the web service will work well but that is not a good solution… What could be the reason for that problem? And how can I solve it?

我接手了一个大学的项目,其中包含一些 Web 服务,并通过将项目导出为 WAR 文件,文件中包含一些库(例如 Axis2),而有些则不包含(休眠、JDBC 驱动程序)。此外,添加到类路径的 jar 尚未导出。所有库都位于硬盘驱动器上的文件夹中,这意味着它们不在 eclipse 文件夹中的某个位置。如果我在用 WinRAR 导出后打开 WAR 文件并手动将库添加到文件中,Web 服务将运行良好,但这不是一个好的解决方案......该问题的原因可能是什么?我该如何解决?

回答by Thorbj?rn Ravn Andersen

The jar dependencies for Eclipse to include in a war file not placed in WEB-INF/lib is notmanaged by the usual "project export/imports" but by a separate panel (3.6: Deployment Assembly, 3.5: Java EE Module Dependencies) in the preferences of the dynamic web project.

Eclipse 包含在未放置在 WEB-INF/lib 中的 war 文件中的 jar 依赖项不是由通常的“项目导出/导入”管理,而是由一个单独的面板(3.6:部署程序集,3.5:Java EE 模块依赖项)管理动态网络项目的偏好。

alt text

替代文字

Note: Since the answer was originally written, Maven has become the defacto packaging tool. Instead of relying on Eclipse features, I would strongly recommend to use Maven packaging instead. It has the additional benefit of making the project instantly usable with all modern IDE's.

注意:由于答案最初是写出来的,Maven 已经成为事实上的打包工具。我强烈建议使用 Maven 打包,而不是依赖 Eclipse 功能。它还有一个额外的好处,就是使项目可以立即与所有现代 IDE 一起使用。