maven打包
1.利用maven-jar-plugin
<build> <plugins> <!-- The configuration of maven-jar-plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <!-- The configuration of the plugin --> <configuration> <!-- Configuration of the archiver --> <archive> <!-- 生成的jar中,不要包含pom.xml和pom.properties这两个文件 --> <addMavenDescriptor>false</addMavenDescriptor> <!-- Manifest specific configuration --> <manifest> <!-- 是否要把第三方jar放到manifest的classpath中 --> <addClasspath>true</addClasspath> <!-- 生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/ --> <classpathPrefix>lib/</classpathPrefix> <!-- 应用的main class --> <mainClass>dbRobot.BeanRobot</mainClass> </manifest> </archive> <!-- 过滤掉不希望包含在jar中的文件 --> <excludes> <exclude>${project.basedir}/xml/*</exclude> </excludes> </configuration> </plugin> <!-- The configuration of maven-assembly-plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.4</version> <!-- The configuration of the plugin --> <configuration> <!-- Specifies the configuration file of the assembly plugin --> <descriptors> <descriptor>src/main/assembly/package.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
再来看package.xml的配置
<assembly> <id>bin</id> <!-- 最终打包成一个用于发布的zip文件 --> <formats> <format>zip</format> </formats> <!-- Adds dependencies to zip package under lib directory --> <dependencySets> <dependencySet> <!-- 不使用项目的artifact,第三方jar不要解压,打包进zip文件的lib目录 --> <useProjectArtifact>false</useProjectArtifact> <outputDirectory>lib</outputDirectory> <unpack>false</unpack> </dependencySet> </dependencySets> <fileSets> <!-- 把项目相关的说明文件,打包进zip文件的根目录 --> <fileSet> <directory>${project.basedir}</directory> <outputDirectory>/</outputDirectory> <includes> <include>README*</include> <include>LICENSE*</include> <include>NOTICE*</include> </includes> </fileSet> <!-- 把项目的配置文件,打包进zip文件的config目录 --> <fileSet> <directory>${project.basedir}\src\main\config</directory> <outputDirectory>config</outputDirectory> <includes> <include>*.xml</include> <include>*.properties</include> </includes> </fileSet> <!-- 把项目的脚本文件目录( src/main/scripts )中的启动脚本文件,打包进zip文件的跟目录 --> <fileSet> <directory>${project.build.scriptSourceDirectory}</directory> <outputDirectory></outputDirectory> <includes> <include>startup.*</include> </includes> </fileSet> <!-- 把项目的脚本文件(除了启动脚本文件),打包进zip文件的script目录 --> <fileSet> <directory>${project.build.scriptSourceDirectory}</directory> <outputDirectory></outputDirectory> <includes> <exclude>startup.*</exclude> </includes> </fileSet> <!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 --> <fileSet> <directory>${project.build.directory}</directory> <outputDirectory></outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> </fileSets> </assembly>
2.利用maven-shade-plugin
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>1.4</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> <!--打包时排除掉数据库连接串和相关配置文件--> <exclude>jdbc.properties</exclude> <exclude>module.config.properties</exclude> </excludes> </filter> </filters> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.xxx.Server</mainClass> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.handlers</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.schemas</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/cxf/bus-extensions.txt</resource> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build>
如果我的文章对你有帮助,就点一下推荐吧.(*^__^*)