如何让 Maven EAR Plugin 自动管理依赖项的类路径?
我大约 12 个月前开始使用 Maven Ear 插件,想了解是否有任何替代品。 Maven 的好处之一是依赖管理,但是使用 Ear 插件后您似乎几乎完全失去了这一点。它将所有依赖的 jar 构建到耳朵中,但实际上不会将它们中的任何一个放在类路径上,而不添加以下配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.4</version>
<configuration>
<version>6</version>
<modules>
<ejbModule>
<groupId>com.mycompany.app</groupId>
<artifactId>MyApplication-ejb</artifactId>
</ejbModule>
<jarModule>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
<jarModule>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
<jarModule>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
</modules>
</configuration>
</plugin>
我是否缺少某些东西,更新版本的插件是否消除了对此的需要,是否有替代方案为你管理这个?我不敢相信,每次我向模块添加依赖项时,我都需要将其添加到 Ear pom 配置中。最令人沮丧的是,即使我记得向上述配置添加一个依赖库,如果它又依赖于其他东西(就像 axis 的情况),我只是在部署耳朵时才发现。
I started using the maven ear plugin about 12 months ago and want to find out if there are any alternatives. One of the benefits of Maven is the dependency management however you seem to almost completely lost this with the ear plugin. It builds all the dependant jar's into the ear but won't actually put any of them on the classpath with out adding the configuration below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.4</version>
<configuration>
<version>6</version>
<modules>
<ejbModule>
<groupId>com.mycompany.app</groupId>
<artifactId>MyApplication-ejb</artifactId>
</ejbModule>
<jarModule>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
<jarModule>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
<jarModule>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
</modules>
</configuration>
</plugin>
Am I missing something does a more recent version of the plugin eliminate the need for this, is there an alternative that manages this for you? I can't believe each time I add a dependency to a module I need to add it to the ear pom configuration. The most frustrating thing is even if I remember to add a dependant library to the above configuration, if that is in turn dependent on something else (as was the case with axis) I am only finding out when I deploy the ear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您应该有一个单独的ear 模块(当然还有ear ),如下所示:
其次,您应该更新ear 插件的版本,因为当前版本是2.6。此外,将您的部件定义为依赖
项您正在使用的配置旨在用于应打包的补充第 3 方库。
First you should have a separate module for the ear (and of course ear ) which looks like the following:
Second you should update the version of the ear plugin, cause the current version is 2.6. Furthermore define your parts as dependencies
The configuration you are using is intended for supplemental 3rd party libs which should be packaged.
除了 khmarbaise 的答案之外,我想指出的是,为了使您的 EJB 模块能够访问库,您必须将其配置为包含
META-INF/MANIFEST.MF
中的依赖项像这样:In addition to the answer of khmarbaise I want to note that in order for your EJB Module to be able to access the libraries you have to configure it to include the dependencies inside the
META-INF/MANIFEST.MF
like this: