我有一个独立的Java应用程序,我想将其打包为:myapp.jar。并将所有相关的jar文件复制到“备用文件夹”。理想情况下,我想让Maven更新META- INF文件,以将所有类路径依赖项jar条目添加到其中。
例如,如果我的项目引用了commons.jar,并且当我使用此插件构建程序集时,它将所有.class文件和程序包从commons.jar复制到myappjar- with-dependencies.jar中。
Maven程序集插件的问题将所有依赖项解压缩到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
<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