4 description: "Maven安装与配置、插件与技巧"
5 navigation: [1.下载, 2.配置, 3.完成, 4.Hello Maven, 更多...]
9 <div class="page-header">
14 官方下载地址:http://maven.apache.org/download.html
16 解压至D:\Development\Apache
21 <div class="page-header">
26 M2_HOME = D:\Development\Apache\apache-maven-3.0.4
27 Path = .;%M2_HOME%\bin
29 添加一个MAVEN_OPTS环境变量来改变JVM的内存
30 MAVEN_OPTS = -Xms256m -Xmx512m
35 <div class="page-header">
41 Apache Maven 3.0.4 (r1232337; 2012-01-17 16:44:56+0800)
42 Maven home: D:\Development\Maven\apache-maven-3.0.4
43 Java version: 1.6.0_29, vendor: Sun Microsystems Inc.
44 Java home: C:\Program Files\Java\jdk1.6.0_29\jre
45 Default locale: zh_CN, platform encoding: GBK
46 OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
51 安装参考: "http://maven.apache.org/download.html#Installation":http://maven.apache.org/download.html#Installation
55 <div class="page-header">
56 <h3>四、Hello Maven <small>第一个Maven工程</small></h3>
61 mvn archetype:generate
63 // 2、提示选择,直接按回车默认选择:maven-archetype-quickstart
64 Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 171:
66 // 3、之后提示选择maven-archetype-quickstart的版本
67 Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
74 Choose a number: 6: // 4、直接按回车默认选择第6项
76 // 5、接着提示输入groupId、artifactId、 version、以及包名package,如下
77 Define value for property 'groupId': : com.linguofeng
78 Define value for property 'artifactId': : helloworld
79 Define value for property 'version': 1.0-SNAPSHOT: :
80 Define value for property 'package': com.linguofeng: : helloworld
81 Confirm properties configuration:
82 groupId: com.linguofeng
83 artifactId: helloworld
88 [INFO] ----------------------------------------------------------------------------
89 [INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
90 [INFO] ----------------------------------------------------------------------------
91 [INFO] Parameter: groupId, Value: com.linguofeng
92 [INFO] Parameter: packageName, Value: helloworld
93 [INFO] Parameter: package, Value: helloworld
94 [INFO] Parameter: artifactId, Value: helloworld
95 [INFO] Parameter: basedir, Value: d:\mvn
96 [INFO] Parameter: version, Value: 1.0-SNAPSHOT
97 [INFO] project created from Old (1.x) Archetype in dir: d:\mvn\helloworld
98 [INFO] ------------------------------------------------------------------------
100 [INFO] ------------------------------------------------------------------------
101 [INFO] Total time: 6:44.171s
102 [INFO] Finished at: Thu Feb 16 13:41:16 CST 2012
103 [INFO] Final Memory: 9M/59M
104 [INFO] ------------------------------------------------------------------------
116 // 编译打包前需要修改pom.xml文件,在</dependencies>标签后增加
120 <groupId>org.apache.maven.plugins</groupId>
121 <artifactId>maven-shade-plugin</artifactId>
122 <version>1.5</version>
125 <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
127 <Main-Class>helloworld.App</Main-Class>
134 <phase>package</phase>
144 // 参考:http://maven.apache.org/plugins/maven-shade-plugin/usage.html
154 java -jar target\helloworld-1.0-SNAPSHOT.jar
158 <div class="page-header">
159 <h3>更多内容 <small>常用插件与技巧</small></h3>
162 <li><a href="http://maven.apache.org/scm/maven-scm-plugin/index.html">maven-scm-plugin</a> 把工程打Tag后发布到SCM(Git、Svn)服务器上,SCM=Software Configuration Management软件配置管理</li>
165 <url>https://github.com/linguofeng/android-dynamic-loading-framework</url>
166 <connection>scm:git:git://github.com/linguofeng/android-dynamic-loading-framework.git</connection>
167 <developerConnection>scm:git:ssh://git@github.com/linguofeng/android-dynamic-loading-framework.git</developerConnection>
171 <artifactId>maven-scm-plugin</artifactId>
172 <version>1.7</version>
174 <scmVersionType>branch</scmVersionType>
175 <scmVersion>master</scmVersion>
179 <li><a href="http://maven.apache.org/plugins/maven-release-plugin/">maven-release-plugin</a> 版本发布插件</li>
181 <distributionManagement>
183 <id>nexus-releases</id>
184 <name>Nexus Release Repository</name>
185 <url>http://127.0.0.1:8081/nexus/content/repositories/releases/</url>
188 <id>nexus-snapshots</id>
189 <name>Nexus Snapshot Repository</name>
190 <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>
191 </snapshotRepository>
192 </distributionManagement>
195 <artifactId>maven-release-plugin</artifactId>
196 <version>2.3.2</version>
198 <autoVersionSubmodules>true</autoVersionSubmodules>
199 <scmCommentPrefix></scmCommentPrefix>
204 $ mvn release:prepare // 此命令会将工程发布到SCM服务器上,需要maven-scm-plugin插件的支持
205 $ mvn release:perform // 此命令会将工程发布到Maven仓库中
207 <li><a href="https://github.com/jayway/maven-android-plugin">maven-android-plugin</a> 开发Android应用的插件,结合 <a href="/pages/favorites/eclipse.html#m2e-android">m2e-android</a> 一起使用</li>
209 通过Maven命令行创建Android工程:https://github.com/rgladwell/m2e-android
211 $ mvn archetype:generate \
212 -DarchetypeArtifactId=android-quickstart \
213 -DarchetypeGroupId=de.akquinet.android.archetypes \
214 -DarchetypeVersion=1.0.8 \
215 -DgroupId=your.company \
216 -DartifactId=my-android-application