好久不見,甚是想念。一日不見,如隔三秋。
從春節到現在已經很久沒有回歸博客園了,今天回來溫習一下maven常用的一些插件的配置,學東西一個很簡單的訣竅就是重復重復再重復,這樣一定能把知識掌握的很牢靠。
話不多說就是上代碼,這部分內容比較簡單,大家自己看注釋理解理解,溫習溫習就好,pom.xml文件如下:
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 2 3 <modelVersion>4.0.0</modelVersion> 4 5 <!-- 坐標、版本以及打包方式 --> 6 <groupId>com.alanlee</groupId> 7 <artifactId>UidpWeb</artifactId> 8 <version>0.0.1-SNAPSHOT</version> 9 <packaging>war</packaging> 10 11 <!-- maven屬性的使用 --> 12 <properties> 13 <plugin.version>2.5</plugin.version> 14 </properties> 15 16 <!-- 依賴配置的使用 --> 17 <dependencies> 18 19 <dependency> 20 <groupId>junit</groupId> 21 <artifactId>junit</artifactId> 22 <version>4.11</version> 23 <!-- 測試范圍有效,在編譯和打包時都不會使用這個依賴 --> 24 <scope>test</scope> 25 </dependency> 26 27 <dependency> 28 <groupId>javax.servlet</groupId> 29 <artifactId>servlet-api</artifactId> 30 <version>2.5</version> 31 <!-- 在編譯和測試的過程有效,最后生成war包時不會加入 --> 32 <scope>provided</scope> 33 </dependency> 34 35 <dependency> 36 <groupId>javax.servlet.jsp</groupId> 37 <artifactId>jsp-api</artifactId> 38 <version>2.2</version> 39 <!-- 在編譯和測試的過程有效,最后生成war包時不會加入 --> 40 <scope>provided</scope> 41 </dependency> 42 43 </dependencies> 44 45 <!-- 用來支持項目發布到私服中,用來配合deploy插件的使用 --> 46 <distributionManagement> 47 <!-- 發布版本 --> 48 <repository> 49 <id>releases</id> 50 <name>public</name> 51 <url>http://10.200.11.21:8081/nexus/content/repositories/releases/</url> 52 </repository> 53 <!-- 快照版本 --> 54 <snapshotRepository> 55 <id>snapshots</id> 56 <name>Snapshots</name> 57 <url>http://10.200.11.21:8081/nexus/content/repositories/snapshots</url> 58 </snapshotRepository> 59 </distributionManagement> 60 61 <!-- 注意體會插件配置的順序,這正體現了一個maven的運行流程 --> 62 <build> 63 <plugins> 64 <!-- 插件使用練習 --> 65 <!-- 清理插件的使用,maven3.0.4會默認使用2.4.1版本的clean插件 --> 66 <plugin> 67 <groupId>org.apache.maven.plugins</groupId> 68 <artifactId>maven-clean-plugin</artifactId> 69 <version>${plugin.version}</version> 70 <executions> 71 <execution> 72 <id>auto-clean</id> 73 <!-- clean生命周期clean階段 --> 74 <phase>clean</phase> 75 <goals> 76 <!-- 執行clean插件的clean目標 --> 77 <goal>clean</goal> 78 </goals> 79 </execution> 80 </executions> 81 </plugin> 82 83 <!-- maven-resources-plugin在maven3.0.4中默認使用2.5版本的resources --> 84 85 <!-- 編譯插件的使用,maven3.0.4會默認使用2.3.2版本的compile插件 --> 86 <plugin> 87 <groupId>org.apache.maven.plugins</groupId> 88 <artifactId>maven-compiler-plugin</artifactId> 89 <version>${plugin.version}</version> 90 <configuration> 91 <!-- 源代碼使用的jdk版本 --> 92 <source>1.7</source> 93 <!-- 構建后生成class文件jdk版本 --> 94 <target>1.7</target> 95 </configuration> 96 </plugin> 97 98 <!-- maven-surefire-plugin插件,maven3.0.4默認使用2.10版本的surefire插件 --> 99 <plugin> 100 <groupId>org.apache.maven.plugins</groupId> 101 <artifactId>maven-surefire-plugin</artifactId> 102 <version>${plugin.version}</version> 103 <configuration> 104 <!-- 改變測試報告生成目錄 ,默認為target/surefire-reports--> 105 <!-- project.build.directory表示maven的屬性,這里指的是構建的目錄下面test-reports,project.build.directory就是pom標簽的值 --> 106 <reportsDirectory>${project.build.directory}/test-reports</reportsDirectory> 107 </configuration> 108 </plugin> 109 110 <!-- war包插件的使用,maven3.0.4會默認使用xxx版本的war插件,建議配置編碼格式和打包名稱 --> 111 <plugin> 112 <groupId>org.apache.maven.plugins</groupId> 113 <artifactId>maven-war-plugin</artifactId> 114 <!-- 利用屬性傳遞版本號 --> 115 <version>${plugin.version}</version> 116 <configuration> 117 <!-- 設置編碼 --> 118 <encoding>UTF-8</encoding> 119 <!-- 設置名稱 --> 120 <warName>ROOT</warName> 121 </configuration> 122 </plugin> 123 124 <!-- maven-install-plugin插件一般不需要配置,maven3.0.4默認使用2.3.1版本的install插件 --> 125 126 <!-- 部署插件的使用,maven3.0.4會默認使用2.7版本的deploy插件 --> 127 <plugin> 128 <groupId>org.apache.maven.plugins</groupId> 129 <artifactId>maven-deploy-plugin</artifactId> 130 <version>${plugin.version}</version> 131 <configuration> 132 <!-- 更新元數據 --> 133 <updateReleaseInfo>true</updateReleaseInfo> 134 </configuration> 135 </plugin> 136 137 </plugins> 138 </build> 139 140 </project>
就是這么簡單。
結束語:這表明了什么?沒錯,就是小Alan又得開始寫一些沒有營養的博文了,既可以幫助自己學習,或許無意間也能給一兩個小伙伴提供那么一丟丟小幫助,堅持寫寫博文既可以幫自己理清一些思路,也可以和大家分享一些小知識,何樂而不為呢?2017,程序員們,讓我們一起搞,搞死搞殘廢,不要慫,就是干,任他風吹雨打,我自巋然不動。
可愛博主:AlanLee
博客地址:http://www.cnblogs.com/AlanLee
本文出自博客園,歡迎大家加入博客園。