Maven构建具有依赖关系的程序集 [英] Maven build assembly with dependencies
问题描述
我有独立的java应用程序,我想打包为:myapp.jar。并将所有相关的罐子复制到备用文件夹。理想情况下,我想让maven更新META-INF文件,将所有类路径依赖项jars条目添加到其中。
I have standalone java application, which i wanted to package as: myapp.jar. And all dependent jars to be copied to 'alternate folder'. Ideally, i would like to have maven update META-INF file to add all classpath dependencies jars entries into it.
例如,如果我的项目引用了commons.jar,当我使用这个插件来构建程序集时,它会将所有.class文件和包从commons.jar复制到myappjar-with-dependencies.jar。
for example, if my project is referencing commons.jar, and when i use this plugin to build assembly, it copies all .class files and packages from commons.jar into myappjar-with-dependencies.jar.
maven的问题程序集插件将所有依赖项解析为myappjar-with-dependencies.jar。
The problem with maven assembly plugin unjars all dependencies into myappjar-with-dependencies.jar.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.core.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
推荐答案
你可以尝试
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.core.App</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/assembly/bin.xml</descriptor>
</descriptors>
</configuration>
</plugin>
src / assembly / bin.xml
src/assembly/bin.xml
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>false</unpack>
<includes>
<include>${artifact}</include>
</includes>
</dependencySet>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<unpack>false</unpack>
<excludes>
<exclude>${artifact}</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
将其设为
mvn clean package assembly:single
详情:http://maven.apache.org/plugins/maven-assembly-plugin/index.html
这篇关于Maven构建具有依赖关系的程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!