maven 常用插件3
轉載:http://www.cnblogs.com/dennyzhangdd/p/5831112.html
?
1.根據項目類型打包:jar/war打包插件。
首先看<packaging>jar</packing>屬性,主流就2種類型。
打成jar包插件:
<plugin>
?? ?<groupId>org.apache.maven.plugins</groupId>
?? ?<artifactId>maven-jar-plugin</artifactId>
?? ?<version>2.4</version>
?? ?<configuration>
?? ??? ?<archive>
?? ??? ??? ?<manifest>
?? ??? ??? ??? ?<addClasspath>true</addClasspath>
?? ??? ??? ??? ?<classpathPrefix>lib/</classpathPrefix>
?? ??? ??? ??? ?<mainClass>com.*.MainClass</mainClass>
?? ??? ??? ?</manifest>
?? ??? ?</archive>
?? ?</configuration>
</plugin>
打成war包插件:
<plugin>
??? <groupId>org.apache.maven.plugins</groupId>
??? <artifactId>maven-war-plugin</artifactId>
??? <version>2.1.1</version>
??? <configuration>
????? <webResources>
??????? <resource>
????????? <directory>src/main/webapp</directory>
????????? <excludes>
??????????? <exclude>**/*.jpg</exclude>
????????? </excludes>
??????? </resource>
????? </webResources>
??? </configuration>
? </plugin>
2. 編譯插件
全局屬性:源碼編碼為utf-8
<properties>
??????? <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
??? </properties>
?
<plugin>
?? ?<artifactId>maven-compiler-plugin</artifactId>
?? ?<version>2.3.2</version>
?? ?<configuration>
?? ??? ?<source>1.6</source>//源代碼編譯版本
?? ??? ?<target>1.6</target>//目標平臺編譯版本
?? ??? ?<includes>
?? ??? ??? ?<include>**/*.java</include>
?? ??? ?</includes>
????????<encoding>${project.build.sourceEncoding}</encoding>//字符集編碼,這里引用全局屬性
?? ?</configuration>
</plugin>
3.拷貝依賴jar包至target/lib下
<plugin> ?
??? <groupId>org.apache.maven.plugins</groupId> ?
??? <artifactId>maven-dependency-plugin</artifactId> ?
??? <version>2.6</version> ?
??? <executions> ?
??????? <execution> ?
??????????? <id>copy-dependencies</id> ?
??????????? <phase>compile</phase> ?
??????????? <goals> ?
??????????????? <goal>copy-dependencies</goal> ?
??????????? </goals> ?
??????????? <configuration> ?
??????????????? <!-- ${project.build.directory}為Maven內置變量,缺省為target --> ?
??????????????? <outputDirectory>${project.build.directory}/lib</outputDirectory> ?
??????????????? <!-- 表示是否不包含間接依賴的包 --> ?
??????????????? <excludeTransitive>false</excludeTransitive> ?
??????????????? <!-- 表示復制的jar文件去掉版本信息 --> ?
??????????????? <stripVersion>false</stripVersion> ?
??????????? </configuration> ?
??????? </execution> ?
??? </executions> ?
</plugin>
4.描述打包插件
它支持各種打包文件格式,包括zip、tar.gz、tar.bz2等等
執行mvn assembly:assembly, 執行成功后會在target文件夾下多出一個以-jar-with-dependencies結尾的JAR包. 這個JAR包就包含了項目所依賴的所有JAR的CLASS.
<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>
<descriptorRefs>
????? <descriptorRef>jar-with-dependencies</descriptorRef>//把依賴的jar包一起打包
????? </descriptorRefs>
??? </configuration>
??? <executions>
????? <execution>
??????? <id>make-assembly</id>
??????? <phase>package</phase>
??????? <goals>
????????? <goal>single</goal>
??????? </goals>
????? </execution>
??? </executions>
</plugin>
5.maven跳過測試用例插件
maven-surefire-plugin 是maven里執行測試用例的插件,不顯示配置就會用默認配置。這個插件的 surefire:test 命令會默認綁定maven執行的 test 階段。
<plugin>
??? <groupId>org.apache.maven.plugins</groupId>
??? <artifactId>maven-surefire-plugin</artifactId>
??? <version>2.19</version>
??? <dependencies>
??????? <dependency>
??????????? <groupId>org.apache.maven.surefire</groupId>
??????????? <artifactId>surefire-junit47</artifactId>
??????????? <version>2.19</version>
??????? </dependency>
??? </dependencies>
??? <configuration>
??????? <skipTests>true</skipTests>//跳過測試用例
??? </configuration>
</plugin>
6.maven自動build插件
<pluginManagement>
?? ?<plugins>
?? ??? ?<plugin>
?? ??? ??? ?<groupId>org.eclipse.m2e</groupId>
?? ??? ??? ?<artifactId>lifecycle-mapping</artifactId>
?? ??? ??? ?<version>1.0.0</version>
?? ??? ??? ?<configuration>
?? ??? ??? ??? ?<lifecycleMappingMetadata>
?? ??? ??? ??? ??? ?<pluginExecutions>
?? ??? ??? ??? ??? ??? ?<pluginExecution>
?? ??? ??? ??? ??? ??? ??? ?<pluginExecutionFilter>
?? ??? ??? ??? ??? ??? ??? ??? ?<groupId>org.apache.maven.plugins</groupId>
?? ??? ??? ??? ??? ??? ??? ??? ?<artifactId>maven-dependency-plugin</artifactId>
?? ??? ??? ??? ??? ??? ??? ??? ?<versionRange>[2.0,)</versionRange>
?? ??? ??? ??? ??? ??? ??? ??? ?<goals>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<goal>copy-dependencies</goal>
?? ??? ??? ??? ??? ??? ??? ??? ?</goals>
?? ??? ??? ??? ??? ??? ??? ?</pluginExecutionFilter>
?? ??? ??? ??? ??? ??? ??? ?<action>
?? ??? ??? ??? ??? ??? ??? ??? ?<ignore/>
?? ??? ??? ??? ??? ??? ??? ?</action>
?? ??? ??? ??? ??? ??? ?</pluginExecution>
?? ??? ??? ??? ??? ??? ?<pluginExecution>
?? ??? ??? ??? ??? ??? ??? ?<pluginExecutionFilter>
?? ??? ??? ??? ??? ??? ??? ??? ?<groupId>org.codehaus.mojo</groupId>
?? ??? ??? ??? ??? ??? ??? ??? ?<artifactId>aspectj-maven-plugin</artifactId>
?? ??? ??? ??? ??? ??? ??? ??? ?<versionRange>[1.0,)</versionRange>
?? ??? ??? ??? ??? ??? ??? ??? ?<goals>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<goal>test-compile</goal>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<goal>compile</goal>
?? ??? ??? ??? ??? ??? ??? ??? ?</goals>
?? ??? ??? ??? ??? ??? ??? ?</pluginExecutionFilter>
?? ??? ??? ??? ??? ??? ??? ?<action>
?? ??? ??? ??? ??? ??? ??? ??? ?<ignore/>
?? ??? ??? ??? ??? ??? ??? ?</action>
?? ??? ??? ??? ??? ??? ?</pluginExecution>
?? ??? ??? ??? ??? ?</pluginExecutions>
?? ??? ??? ??? ?</lifecycleMappingMetadata>
?? ??? ??? ?</configuration>
?? ??? ?</plugin>
?? ?</plugins>
</pluginManagement>
轉載于:https://www.cnblogs.com/FlyAway2013/p/6896991.html
總結
以上是生活随笔為你收集整理的maven 常用插件3的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java的this、super和fina
- 下一篇: 关于椭圆的积分变量替换