使用Maven在jar中包含依赖项 [英] Including dependencies in a jar with Maven

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

问题描述

有没有办法强制maven(2.0.9)在一个jar文件中包含所有依赖项?

Is there a way to force maven(2.0.9) to include all the dependencies in a single jar file?

我有一个项目构建成单个jar文件。我希望将依赖项中的类复制到jar中。

I have a project the builds into a single jar file. I want the classes from dependencies to be copied into the jar as well.

更新:我知道我不能只包含一个jar文件一个jar文件。我正在寻找一种方法来解压缩指定为依赖项的jar,并将类文件打包到我的jar中。

Update: I know that I cant just include a jar file in a jar file. I'm searching for a way to unpack the jars that are specified as dependencies, and package the class files into my jar.

推荐答案

您可以使用带有jar-with-dependencies描述符的maven-assembly插件来完成此操作。这是我们的一个pom.xml中的相关块:

You can do this using the maven-assembly plugin with the "jar-with-dependencies" descriptor. Here's the relevant chunk from one of our pom.xml's that does this:

  <build>
    <plugins>
      <!-- any other plugins -->
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    </plugins>
  </build>

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

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