如何使用maven创建一个可运行的jar,其中包含一个单独的"lib"文件夹(不是超级jar)中的依赖项

Jas*_*ler 4 java executable-jar maven

我正在尝试使用Maven创建一个可执行jar文件,其中包含单独目录中的依赖项.我已经看到很多关于创造"uberjar"的问题 - 我不希望如此.我想要的是将依赖项复制到像这样的"lib"目录中(以及MANIFEST.MF带有ClassPath指向它们的条目的jar 文件):

/myApp
  myApp.SNAPSHOT-1.0.jar
  /lib
    hibernate.jar
    log4j.jar
    ...
Run Code Online (Sandbox Code Playgroud)

作为一个额外的奖励,如果我可以复制/src/main/resources/*/myApp/conf然后压缩整个/myApp目录,那将myApp.zip是很好的.

编辑:我使用maven-dependency-plugin和maven-resources-plugin以及maven-jar-plugin.这是我在我的pom.xml中包含的内容(它将运行时依赖项复制到/ target/release/lib,以便我可以压缩/目标/发布并准备好了):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <includeScope>runtime</includeScope>
                <outputDirectory>
                    ${project.build.directory}/release/lib
                </outputDirectory>
             </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
      <execution>
        <id>copy-resources</id>
        <!-- here the phase you need -->
        <phase>package</phase>
        <goals>
          <goal>copy-resources</goal>
        </goals>
        <configuration>
          <outputDirectory>${project.build.directory}/release</outputDirectory>
          <resources>          
            <resource>
              <directory>src/main/config</directory>
              <filtering>true</filtering>
            </resource>
          </resources>              
        </configuration>            
      </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <outputDirectory>
                    ${project.build.directory}/release/lib
                </outputDirectory>
             </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

Gre*_*ver 5

maven依赖插件有一个复制依赖目标,可以做你想要的.

mvn dependency:copy-dependencies
Run Code Online (Sandbox Code Playgroud)

请参阅此处了解可用选项.即'outputDirectory'将依赖项复制到/ lib