我有一个java应用程序并使用maven-assembly-plugin我想在我的发行版中将我的依赖项添加到/ lib文件夹。
在一个Web项目中它很简单,因为jar已经在war文件中了。由于所有外部jar都在我的本地.m2存储库中,所以我不想在标准的java应用程序中做到这一点。
答案 0 :(得分:5)
我经常使用这个程序集配置
<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">
<id>assembly</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<outputFileNameMapping>${artifact.groupId}.${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
<useProjectArtifact>false</useProjectArtifact>
<!-- you may place excludes here -->
</dependencySet>
</dependencySets>
<files>
<file>
<outputDirectory>/</outputDirectory>
<source>${project.build.directory}/${project.artifactId}-${project.version}.jar</source>
<destName>${project.artifactId}.jar</destName>
</file>
</files>
<fileSets>
<fileSet>
<outputDirectory>config</outputDirectory>
<directory>config</directory>
</fileSet>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>src/main/bin</directory>
</fileSet>
</fileSets>
</assembly>
然后我在我的POM中用
引用它<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>create-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
如果您还需要可运行的JAR :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifestEntries>
<Class-Path>config/</Class-Path>
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<classpathLayoutType>custom</classpathLayoutType>
<customClasspathLayout>$${artifact.groupId}.$${artifact.artifactId}.$${artifact.extension}</customClasspathLayout>
</manifest>
</archive>
</configuration>
</plugin>