maven ejb项目-带有依赖项的包
有没有办法将 Maven ejb 项目的依赖项打包到最终的 jar 中?
我通常使用单独的 Ear 项目并将 ejb 作为依赖项包含在内 - 它将以这种方式自动填充 lib 文件夹。然而,这似乎有点浪费——有一个项目只是为了构建耳朵。
现在我有:
<artifactId>projectname</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- without this, the datetime stamp unique id's will be appended to classpath items -->
<!-- see: http://maven.apache.org/shared/maven-archiver/examples/classpath.html#Snapshot -->
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
我需要将包装类型设置为耳朵吗?我可以在独立的 ejb jar 中包含传递依赖项吗?如果我设置为ear,我该如何配置ear插件?
提前致谢!
Is there a way to pack the dependencies of a maven ejb project in with the final jar?
I typically use a separate ear project and include the ejb as a dependency - it will fill out the lib folder automatically this way. However, this seems a bit wasteful - to have a project just to build the ear.
Right now I have:
<artifactId>projectname</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- without this, the datetime stamp unique id's will be appended to classpath items -->
<!-- see: http://maven.apache.org/shared/maven-archiver/examples/classpath.html#Snapshot -->
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
Do I need to set the packaging type to ear? Can I include transitive dependencies in a standalone ejb jar? If I set it to ear, how do I config the ear plugin?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Maven Shade 插件 可以将依赖项打包到 JAR 中。它将从项目的所有依赖项中提取类/资源,并将它们打包到最终的 JAR 中。
这应该足以打包所有依赖项:
但是,这样做有一些缺点。
除非您有充分的理由不这样做,否则我建议您坚持构建 EAR。
The Maven Shade Plugin can package dependencies in with the JAR. It will extract the classes/resources from all the project's dependencies on package them in with the final JAR.
This should be enough to package all your dependencies:
There are disadvantages to doing this, however.
Unless you have good reason not to, I'd recommend you stick with building an EAR.
我认为没有直接的方法可以做到这一点。相反,可以将其创建为带有 Ear 和 ejb 模块的模块项目。这并不完全是我想要的,但它有效并且比单独的项目更好。
I don't think there is a direct way to do this. Instead, what can be done is to create it as a module project with an ear and an ejb module. It isn't exactly what I wanted, but it works and is better than separate projects.