maven ejb项目-带有依赖项的包

发布于 2024-12-05 19:03:20 字数 1282 浏览 0 评论 0原文

有没有办法将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浊酒尽余欢 2024-12-12 19:03:20

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

这应该足以打包所有依赖项:

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

但是,这样做有一些缺点。

  • 不同 JAR 中具有相同名称的多个资源可能会导致问题(例如 /META-INF/services/...)。您可以使用 Shade 的资源转换器,但它可能会变得混乱。
  • 一旦部署,跟踪哪些 JAR 是项目中的依赖项就不那么容易了(您必须回顾 POM 而不是仅仅查看 EAR)。

除非您有充分的理由不这样做,否则我建议您坚持构建 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:

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

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

梦在深巷 2024-12-12 19:03:20

我认为没有直接的方法可以做到这一点。相反,可以将其创建为带有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文