<pluginManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</pluginManagement>
</build>
打war包的插件
<plugins>
<plugin><!--打war包的插件-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<<version>2.6</version>
<configuration><!--打包时排除的文件-->
<packagingExcludes>WEB-INF/web2.xml</packagingExcludes> </configuration>
</plugin>
</plugins>
排除的文件如下图所示
打包jar文件时,配置manifest文件,加入lib包的jar依赖
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>target/classes/</classesDirectory>
<archive>
<manifest>
<mainClass>com.alibaba.dubbo.container.Mainxxxx</mainClass>
<!-- 打包时 MANIFEST.MF文件不记录的时间戳版本否则SNAPSHOT类型的依赖包xxx-1.3.0-20121225.012733.jar -->
<useUniqueVersions>false</useUniqueVersions><!--不要时间戳-->
<!-- 增加classpath的路径--> <addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
将第三方依赖放入lib的一个单独目录 实际上打出的xx.jar里并没有lib目录 思想就是将第三方依赖的jar放入lib中然后将lib外置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<type>jar</type>
<includeTypes>jar</includeTypes>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!--打包时带源码-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
打成一个xxx0.0.1-SNAPSHOT.jar,里面包括了依赖的第三方的jar并且配置了包Main方法入口
<plugin>
<!--将依赖的三方jar包打进最终的jar包中-->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest><!--jar包执行的入口主方法-->
<mainClass>com.xxx.MainJavaxxx</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase><!--打包阶段执行-->
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>