Eclipse 中部署程序集和 J2EE 模块依赖项之间的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11126044/
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 18:23:48  来源:igfitidea点击:

Difference between Deployment Assembly and J2EE Module Dependencies in Eclipse

javaeclipsejakarta-eeeclipse-indigoeclipse-3.5

提问by chaosguru

When using a Eclipse 3.7 Indigo for Java EE Developers, there is something called Deployment Assembly. I could find on google and understood that it is similar to the J2EE Module dependencieswhere in we could select the jar and which goes and sits in the EAR folder or in WEB-INF/lib in case of WAR. Now the doubt I have is,

为 Java EE 开发人员使用 Eclipse 3.7 Indigo 时,有一个叫做Deployment Assembly 的东西。我可以在 google 上找到并理解它类似于 J2EE 模块依赖项,我们可以在其中选择 jar,并且在 WAR 的情况下,它位于 EAR 文件夹或 WEB-INF/lib 中。现在我的疑问是,

I have a JavaProject Dependencies. I have added all the dependent Jars via classpathvariable. Now the DependenciesProject is added as dependency to my Web Project TestWebProject. The compilation of the Web Project is correct but during runtime I get an error because some jar was not found. I could fix this my include jar in Deployment Assembly of DependenciesProject, which is a standalone project.

我有一个 JavaProject Dependencies。我已经通过类路径变量添加了所有依赖的 Jars 。现在Dependencies项目作为依赖项添加到我的 Web 项目TestWebProject。Web 项目的编译是正确的,但在运行时我收到一个错误,因为找不到某些 jar。我可以在依赖项项目的部署程序集中包含 jar 来解决这个问题,这是一个独立的项目。

The question is that, why I had to fix the jar in deployment assembly since ,first, its a standalone project and second is if I would not have this deployment assembly , how could this be fixed?

问题是,为什么我必须在部署程序集中修复 jar,因为首先,它是一个独立的项目,其次是如果我没有这个部署程序集,如何修复?

回答by BalusC

I could find on google and understood that it is similar to the J2EE Module dependencies

我可以在谷歌上找到并理解它类似于 J2EE 模块依赖项

It was called "J2EE Module Dependencies" until with Eclipse 3.5. After that version, it was renamed to "Deployment Assembly". But it's effectively the same in case of Java EE web projects.

在 Eclipse 3.5 之前,它被称为“J2EE 模块依赖项”。在那个版本之后,它被重命名为“部署程序集”。但是对于 Java EE Web 项目来说实际上是相同的。



The question is that, why I had to fix the jar in deployment assembly since its a standalone project

问题是,为什么我必须在部署程序集中修复 jar,因为它是一个独立项目

Because this way Eclipse will autobuild a JAR file of the project and put in /WEB-INF/libof the web project's deployment. If you don't do that, the JAR isn't available during webapp's runtime, but only during compiletime and Eclipse expects that you've already built and placed it anywhere else in runtime classpath, e.g. server's own /lib.

因为这样 Eclipse 会自动构建项目的 JAR 文件并放入/WEB-INF/libweb 项目的部署中。如果您不这样做,则 JAR 在 webapp 运行时不可用,但仅在编译时可用,Eclipse 预计您已经构建并将其放置在运行时类路径中的任何其他位置,例如服务器自己的/lib.



if I would not have this deployment assembly , how could this be fixed?

如果我没有这个部署程序集,如何解决这个问题?

Manually build/export the JAR and drop in webapp's own /WEB-INF/libor server's own /lib. The "Deployment Assembly" configuration is however more easy and the recommended way.

手动构建/导出 JAR 并放入 webapp 自己的/WEB-INF/lib或服务器自己的/lib. 然而,“部署程序集”配置更简单,也是推荐的方式。

See also:

也可以看看:

回答by Konstantin Komissarchik

When assembling a WAR, Eclipse cannot tell just by looking at your build path dependencies whether they are something that should be bundled in WAR's WEB-INF/lib directory or if they are something that you expect to be available on your server classpath. Extra metadata is needed to differentiate among those cases.

在组装 WAR 时,Eclipse 无法仅通过查看构建路径依赖项来判断它们是否应该捆绑在 WAR 的 WEB-INF/lib 目录中,或者它们是否是您希望在服务器类路径上可用的东西。需要额外的元数据来区分这些情况。

If you look in your problems view, you should see numerous warnings that look like this:

如果您查看问题视图,您应该会看到许多如下所示的警告:

"Classpath entry [something] will not be exported or published..."

“类路径条目 [某些东西] 不会被导出或发布......”

Right click on these and select "Quick Fix". You will see a dialog with available fixes. One of them is going to say something like "Mark the associated classpath entry as publish/export dependency...". Use that option.

右键单击这些并选择“快速修复”。您将看到一个包含可用修复程序的对话框。其中一个会说“将关联的类路径条目标记为发布/导出依赖项...”。使用该选项。

The above will make a slight alteration to your Java project's .classpath file to tag the dependencies for inclusion in the assembly. You can test without running by exporting a WAR file and checking the contents of WEB-INF/lib folder.

上面的代码将对 Java 项目的 .classpath 文件稍作改动,以标记要包含在程序集中的依赖项。您可以通过导出 WAR 文件并检查 WEB-INF/lib 文件夹的内容来进行测试,而无需运行。

回答by Preetham R U

Build path - place your jar's here directly, it will be available for code runtime and compile time.

构建路径 - 将您的 jar 直接放在此处,它将可用于代码运行时和编译时。

Deployment assembly - eclipse expects the projects under this path to be bundled and deployed as .jar in web-inf/lib folder. So that it is available for both compile time and run time. If the project is not deployed in deployment assembly then the code is available only for compile time, eclipse won't bundle it and at run-time dependent projects are unavailable to the code.

部署程序集 - eclipse 期望此路径下的项目被捆绑并部署为 web-inf/lib 文件夹中的 .jar。这样它在编译时和运行时都可用。如果项目未部署在部署程序集中,则代码仅在编译时可用,eclipse 不会捆绑它,并且在运行时依赖项目对代码不可用。