1.先在pom.xml文件中添加assembly打包插件
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptors>
<descriptor>assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
说明:1.需要修改的可能就是descriptors标签下面的打包配置文件目录,指定assembly.xml的路径.
2.可以添加多个打包配置文件,进行多种形式打包,比如添加assembly2.xml路径
2.assembly.xml,下面这个是完整的打包配置
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>test</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>{project.basedir}/bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
<includes>
<include>*.sh</include>
</includes>
</fileSet>
</fileSets>
<moduleSets>
<moduleSet>
<binaries>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
说明:1.formats限定打包格式,支持常见多种格式,zip,gz什么的
2.filesets标签指定要打包的目录.点对点打包,将某一个目录打包到某一个目录下,可以选择排除某些目录和包含某些目录
3.dependencySets标签指定将scope范围内的jar包打包到指定目录
4.moduleSets标签指定是否将项目下的木块打包到指定目录,可以选择部分目录
3.运行mvn package
网友评论