tomcat
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.1</version> <configuration> <path>/device-manager-provider</path> <uriEncoding>utf-8</uriEncoding> <port>8001</port> <server>tomcat</server> <systemProperties> <systemProperty> <name>JAVA_OPTS</name> <value>-Xms256m -Xmx768m -XX:+UseConcMarkSweepGC -XX:MaxPermSize=256m -XX:NewRatio=6 -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled </value> </systemProperty> </systemProperties> </configuration> </plugin>
dependency
maven-dependency-plugin是处理与依赖相关的插件。它有很多可用的goal,大部分是和依赖构建、分析和解决相关的goal,这部分goal可以直接用maven的命令操作,例如:mvn dependency:tree、mvn dependency:analyze;这类操作在平时的maven应用中很少会用到。这里主要介绍除此之外的、用得最多的几个操作:copy, copy-dependencies和它们对应的unpack, unpack-dependencies
<plugin> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>unpack</id> <phase>package</phase> <!--在打包的的生命周期中,绑定unpack goal--> <goals> <goal>unpack</goal> <!--goal 为解压--> </goals> <configuration> <artifactItems> <artifactItem> <!--指定解压的jar包--> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>${project.parent.version}</version> <!--把解压出来的包中的指定文件输出到指定目录,${project.build.directory}默认为target --> <outputDirectory>${project.build.directory}/dubbo</outputDirectory <!--把解压出来的包中的指定文件输出到指定目录--> <includes>META-INF/assembly/**</includes> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<phase>package</phase> <!--在打包的生命周期中完成copy的goal-->
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems> <!--要copy的内容-->
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</artifactItem>
<artifactItem>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
<outputDirectory>lib2</outputDirectory>
</artifactItem>
</artifactItems>
<outputDirectory>lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<!--这里没有指定任何配置,所有的参数都用默认值,
则当前工程的所有依赖(直接、间接的)都会被拷到target/dependency目录下>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
<!--要排除所有camel的依赖-->
<configuration>
<excludeGroupIds>org.apache.camel</excludeGroupIds>
</configuration>
<!--要排除除camel-spring外的所有其他依赖-->
<configuration>
<includeArtifactIds>camel-spring</includeArtifactIds>
</configuration>
assembly打包
assembly-plugin 打包,把需要打包的jar包,资源都复制到目标文件中,jar包之间不会合并
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<!--assembly.xml配置文件路径-->
<configuration>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals><goal>single</goal></goals>
</execution>
</executions>
</plugin>assembly.xml
<assembly>
<id>assembly</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<!--把target/dubbo/META-INF/assembly/bin 输出到bin 目录-->
<directory>${project.build.directory}/dubbo/META-INF/assembly/bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<!--把src/main/assembly/conf 输出到conf 目录-->
<directory>src/main/assembly/conf</directory>
<outputDirectory>conf</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
</fileSets>
<!--把依赖包输出到lib目录-->
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
发布包到仓库 distributionManagement
pom:
<distributionManagement>
<repository>
<id>xxx-releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.41.25:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>xxx-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.41.25:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
maven settings.xml
<server>
<id>xxx-releases</id>
<username>deployment</username>
<password>xxx</password>
</server>
<server>
<id>xxx-snapshots</id>
<username>deployment</username>
<password>xxx</password>
</server>
</servers>
maven-shade-plugin 打包
shade-plugin把所有依赖的包,文件都整合到一个jar包中
<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>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<artifactSet>
<!--jar中包含的lib-->
<includes>
<include>com.alibaba:hessian-lite</include>
<include>com.alibaba:dubbo-common</include>
<include>com.alibaba:dubbo-remoting-api</include>
<include>com.alibaba:dubbo-remoting-netty</include>
<include>com.alibaba:dubbo-remoting-mina</include>
</includes>
<!--jar中排除的lib-->
<excludes>
<exclude>junit:junit</exclude>
<exclude>jmock:*</exclude>
<exclude>*:xml-apis</exclude>
<exclude>org.apache.maven:lib:tests</exclude>
<exclude>log4j:log4j:jar:</exclude>
</excludes>
</artifactSet>
<transformers>
<!-- 是否生成含有main函数的可执行jar
<transformers>
<transformer implementation = "org.apache.maven.plugins.shade.resource.MainifestResourceTransformer">
<mainClass>mainclass</mainClass>
</transformer>
-->
<!--加入资源文件-->
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/com.alibaba.dubbo.common.compiler.Compiler</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/com.alibaba.dubbo.common.extension.ExtensionFactory</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>