包含 Maven 依赖项的客户端 JAR

发布于 2024-12-26 14:00:38 字数 224 浏览 0 评论 0原文

我正在构建一个包含使用 Spring 的客户端模块的服务。将实现客户端的服务不包含 spring,但它依赖于依赖于 Spring 的客户端。理想情况下,我希望客户端在 JAR 中包含所需的 Spring 依赖项,但我似乎不知道如何实现这一点。我见过一些使用 maven- assembly-plugin 的不同示例,但我宁愿不必使用“mvn clean package”之外的其他东西来完成此任务。

任何帮助表示赞赏。

I'm building a service which contains a client module which is using Spring. The service which will be implementing the client does not contain spring but it has a dependency on the client which has dependencies on Spring. Ideally I would like the client to include the needed Spring dependencies in the JAR but I can't seem to figure out how to accomplish this. I've seen a few different examples of using maven-assembly-plugin but I would prefer to not have to use something other than "mvn clean package" to accomplish this.

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

晚风撩人 2025-01-02 14:00:38

maven-shade-plugin 允许您构建一个包含一些内容的 uber-jar (或全部)您的依赖项。它应该允许您做您需要做的事情。

The maven-shade-plugin allows you to build an uber-jar containing some (or all) of your dependencies. It should allow you to do what you need.

心作怪 2025-01-02 14:00:38

通过将程序集插件的单一目标绑定到项目的构建生命周期,您可以通过运行 mvn clean package 来完成您想要的任务。

usage 页面剪切/粘贴 pom 配置以执行此操作 当然,您可以调整插件

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2.2</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      [...]
</project>

以使用不同的预定义描述符,甚至使用单独的描述符文件。

By binding the assembly plugin's single goal to the project's build lifecycle, you can accomplish what you want by running mvn clean package.

Cut/pasting the pom configuration to do this from the usage page of the plugin,

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2.2</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      [...]
</project>

Of course, you would tweak either either to use a different predefined descriptor or even use a separate descriptor file.

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