使用Maven,我如何构建一个包含我的项目jar和所有依赖jar的distributable? [英] With Maven, how can I build a distributable that has my project's jar and all of the dependent jars?

查看:183
本文介绍了使用Maven,我如何构建一个包含我的项目jar和所有依赖jar的distributable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目(类型'jar')(显然)构建了一个jar。但该项目有很多依赖性。我希望Maven构建一个包或程序集,其中包含我的jar,所有依赖的jar和一些脚本(启动应用程序等)。

I have a project (of type 'jar') that (obviously) builds a jar. But that project has many dependencies. I'd like Maven to build a "package" or "assembly" that contains my jar, all the dependent jars, and some scripts (to launch the application, etc.)

最好的方法是什么?具体来说,什么是让家属进入装配的最佳方法?

What's the best way to go about this? Specifically, what's the best way to get the dependents into the assembly?

推荐答案

对于单个模块,我会使用一个程序集看起来像下面一个( src / assembly / bin.xml ):

For a single module, I'd use an assembly looking like the following one (src/assembly/bin.xml):

<assembly>
  <id>bin</id>
  <formats>
    <format>tar.gz</format>
    <format>tar.bz2</format>
    <format>zip</format>
  </formats>
  <dependencySets>
    <dependencySet>
      <unpack>false</unpack>
      <scope>runtime</scope>
      <outputDirectory>lib</outputDirectory>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <directory>src/main/command</directory>
      <outputDirectory>bin</outputDirectory>
      <includes>
        <include>*.sh</include>
        <include>*.bat</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>

要使用此程序集,请将以下配置添加到pom.xml:

To use this assembly, add the following configuration to your pom.xml:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
      <descriptors>
        <descriptor>src/assembly/bin.xml</descriptor>
      </descriptors>
    </configuration>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

在此示例中,位于 src / main /命令下的启动/停止脚本并捆绑在 bin 中,依赖项捆绑在 lib 中。根据您的需求进行定制。

In this sample, start/stop scripts located under src/main/command and are bundled into bin, dependencies are bundled into lib. Customize it to suit your needs.

这篇关于使用Maven,我如何构建一个包含我的项目jar和所有依赖jar的distributable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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