java maven ejb 项目 - 带有依赖项的包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7494927/
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
maven ejb project - package with dependencies
提问by javamonkey79
Is there a way to pack the dependencies of a maven ejb project in with the final jar?
有没有办法将 maven ejb 项目的依赖项打包到最终的 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.
我通常使用单独的 ear 项目并将 ejb 作为依赖项包含在内 - 它会以这种方式自动填充 lib 文件夹。然而,这似乎有点浪费 - 有一个项目只是为了建造耳朵。
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?
我需要将包装类型设置为耳朵吗?我可以在独立的 ejb jar 中包含传递依赖项吗?如果我设置为ear,我该如何配置ear插件?
Thanks in advance!
提前致谢!
回答by prunge
The Maven Shade Plugincan 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.
在Maven的阴影插件可以与jar包的依赖关系。它将从项目的所有依赖项中提取类/资源,并将它们打包到最终的 JAR 中。
This should be enough to package all your dependencies:
这应该足以打包所有依赖项:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
There are disadvantages to doing this, however.
但是,这样做也有缺点。
- Multiple resources with the same name in different JARs can cause problems (e.g. /META-INF/services/...). You can use Shade's resource transformers, but it can get messy.
- Not as easy to track what JARs are dependencies in your project once deployed (you'd have to refer back to the POM instead of just looking at the EAR).
- 不同 JAR 中具有相同名称的多个资源可能会导致问题(例如 /META-INF/services/...)。您可以使用 Shade 的资源转换器,但它可能会变得混乱。
- 部署后跟踪哪些 JAR 是项目中的依赖项并不容易(您必须回溯到 POM 而不是只查看 EAR)。
Unless you have good reason not to, I'd recommend you stick with building an EAR.
除非您有充分的理由不这样做,否则我建议您坚持构建 EAR。
回答by javamonkey79
I don't think there is a direct way to do this. Instead, what canbe 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.
我认为没有直接的方法可以做到这一点。相反,可以做的是将其创建为带有一个ear 和一个ejb 模块的模块项目。这不完全是我想要的,但它有效并且比单独的项目更好。