日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

maven 常用插件3

發布時間:2025/6/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 maven 常用插件3 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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>

posted on 2017-05-24 02:30 CanntBelieve 閱讀(...) 評論(...) 編輯 收藏

轉載于:https://www.cnblogs.com/FlyAway2013/p/6896991.html

總結

以上是生活随笔為你收集整理的maven 常用插件3的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。