maven 常用插件
1 maven-compiler-plugin
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
2 maven-dependency-plugin 把依赖的jar包拷到指定目录下
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-dependencies</id>
- <phase>process-resources</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <excludeScope>provided</excludeScope>
- <excludeArtifactIds>
- module1,module2
- </excludeArtifactIds>
- <outputDirectory>${project.build.directory}/lib</outputDirectory>
- </configuration>
- </execution>
- <execution>
- <id>copy-modules</id>
- <phase>process-resources</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <includeArtifactIds>
- module1,module2
- </includeArtifactIds>
- <outputDirectory>${project.build.directory}/lib/modules</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
3 maven-resources-plugin 把依赖的资源拷到指定目录下
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>2.6</version>
- <executions>
- <execution>
- <id>copy-resources</id>
- <!-- here the phase you need -->
- <phase>validate</phase>
- <goals>
- <goal>copy-resources</goal>
- </goals>
- <configuration>
- <outputDirectory>${basedir}/target/test-classes</outputDirectory>
- <resources>
- <resource>
- <directory>${basedir}/src/main/webapp/WEB-INF/config</directory>
- <filtering>true</filtering>
- </resource>
- </resources>
- </configuration>
- </execution>
- </executions>
- </plugin>
4 maven-jar-plugin 打jar包配置
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <excludes>
- <exclude>**/config/*</exclude>
- </excludes>
- </configuration>
- </plugin>
5 maven-shade-plugin 把依赖的lib打包到一个jar
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <version>2.2</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <artifactSet>
- <includes>
- <include>thirdparty.mysql:mysql-connector-java</include>
- </includes>
- </artifactSet>
- </configuration>
- </execution>
- </executions>
- </plugin>
6 maven-war-plugin web工程需要这个
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-war-plugin</artifactId>
- <configuration>
- <webappDirectory>../out</webappDirectory>
- <warSourceDirectory>webapp</warSourceDirectory>
- </configuration>
- </plugin>
7 maven-assembly-plugin 强大的归档利器
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.2.1</version>
- <configuration>
- <descriptors>
- <descriptor>src/main/assembly/assembly.xml</descriptor>
- </descriptors>
- <outputDirectory>${basedir}/deploy</outputDirectory>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
其中, assembly.xml 文件定义了内部各个目录的资源生成策略
- <?xml version="1.0" encoding="UTF-8"?>
- <assembly>
- <id>distribution</id>
- <formats>
- <format>dir</format>
- </formats>
- <includeBaseDirectory>false</includeBaseDirectory>
- <fileSets>
- <fileSet>
- <directory>${project.build.directory}</directory>
- <outputDirectory>/lib</outputDirectory>
- <includes>
- <include>${project.artifactId}-${project.version}.jar</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>${project.build.directory}/lib</directory>
- <outputDirectory>/lib</outputDirectory>
- </fileSet>
- <fileSet>
- <directory>${basedir}/src/main/assembly/dist/</directory>
- <outputDirectory>/</outputDirectory>
- <includes>
- <include>**</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>${basedir}/src/main/assembly/dist/bin</directory>
- <outputDirectory>/bin</outputDirectory>
- <includes>
- <include>**</include>
- </includes>
- <fileMode>0755</fileMode>
- </fileSet>
- <fileSet>
- <directory>${basedir}/../other-module/src/main/resources/</directory>
- <outputDirectory>/etc</outputDirectory>
- <includes>
- <include>**</include>
- </includes>
- </fileSet>
- </fileSets>
- </assembly>
来自Apache的完整插件列表在:http://maven.apache.org/plugins/index.html
来自Codehaus的完整插件列表在:http://mojo.codehaus.org/plugins.html
--------------------------------------
欢迎您,进入 我系程序猿 的cnBlog博客。
你不能改变你的过去,但你可以让你的未来变得更美好。一旦时间浪费了,生命就浪费了。
You cannot improve your past, but you can improve your future. Once time is wasted, life is wasted.
--------------------------------------