给出一个带有依赖项列表的pom.xml文件,是否有一个Maven命令将所有这些jar捆绑到一个大jar中? 我不想在构建中包含.class文件-我只想在构建中包含库.class / jar文件-有办法吗?
我看到了这个插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/Crunchify/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
${project.build.directory}/Crunchify/lib
的路径,也没有任何内容写入该位置,我也看到了这个通用插件:
http://maven.apache.org/plugins/maven-assembly-plugin/usage.html
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</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>
但是当我使用pom.xml中的mvn clean package
运行maven-assembly-plugin
时,看不到任何新的jar文件。
答案 0 :(得分:0)
使用jar-with-dependencies
和single~package
,您陷入了程序集的“ GOTCHAS”之一(在打包(未完成)之前,没有任何程序可以组装)。
但是将这两个插件结合使用,将会起作用:
<project>
...
<!-- many many dependencies -->
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-deps</id>
<phase>process-sources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>big-big-jar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/dependency</directory>
<outputDirectory />
<includes>
<!-- attention: maybe you need more ... zip, tz.gz.bz. -->
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
mvn clean package
...
BUILD SUCCESS
...将为您带来:
.. file,包含所有临时依赖 您的.jar /类。