maven ejb项目 - 包含依赖项 [英] maven ejb project - package with dependencies

查看:532
本文介绍了maven ejb项目 - 包含依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用最终的jar包装maven ejb项目的依赖项?

Is there a way to pack the dependencies of a maven ejb project in with the final jar?

我通常使用一个单独的ear项目并将ejb作为依赖项包含在内 - 它会以这种方式自动填充lib文件夹。然而,这似乎有点浪费 - 有一个项目只是为了建立耳朵。

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.

现在我有:

<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中包含传递依赖吗?如果我把它设置为耳朵,我该如何配置耳塞?

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?

提前致谢!

推荐答案

Maven Shade插件可以打包依赖项在JAR中。它将从所有项目的依赖项中提取类/资源,并使用最终的JAR将它们打包。

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:

<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.


  • 不同JAR中具有相同名称的多个资源可能会导致问题(例如/ META-INF / services / ...)。您可以使用Shade的资源转换器,但它可能会变得混乱。

  • 在部署项目时,不容易跟踪项目中JAR的依赖关系(您不得不再次参考POM)只看EAR)。

除非你有充分的理由不这样做,否则我建议你坚持建立一个EAR。

Unless you have good reason not to, I'd recommend you stick with building an EAR.

这篇关于maven ejb项目 - 包含依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆