方法1:
1.使用:
mvn archetype:generate
然后按要求输入相关的配置:
(1)可以跳过filter:
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive co ntains): 777:
(2)然后按要求输入:
a.版本号
b.groupId
c:artifactId
d:version
e:package:可跳过
f:Y:确认
记录:
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive co ntains): 777: Choose org.apache.maven.archetypes:maven-archetype-quickstart version: 1: 1.0-alpha-1 2: 1.0-alpha-2 3: 1.0-alpha-3 4: 1.0-alpha-4 5: 1.0 6: 1.1 Choose a number: 6: 6 Define value for property 'groupId': : org.xubo.maven.test Define value for property 'artifactId': : maven_ch2 Define value for property 'version': 1.0-SNAPSHOT: : 0.0.1-SNAPSHOT Define value for property 'package': org.xubo.maven.test: : Confirm properties configuration: groupId: org.xubo.maven.test artifactId: maven_ch2 version: 0.0.1-SNAPSHOT package: org.xubo.maven.test Y: : Y
(3)然后maven会生成相应的project
pom.xml:
<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"> <modelVersion>4.0.0</modelVersion> <groupId>org.xubo.maven.test</groupId> <artifactId>maven_ch2</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>maven_ch2</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
2.然后进入project进行测试
<pre name="code" class="plain">D:\all\idea\mavenTest\maven_ch2>mvn test [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building maven_ch2 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven_ch2 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory D:\all\idea\mavenTest\maven_ch2\src\m ain\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven_ch2 --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to D:\all\idea\mavenTest\maven_ch2\target\classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ma ven_ch2 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory D:\all\idea\mavenTest\maven_ch2\src\t est\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven_c h2 --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to D:\all\idea\mavenTest\maven_ch2\target\test-cl asses [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven_ch2 --- [INFO] Surefire report directory: D:\all\idea\mavenTest\maven_ch2\target\surefir e-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running org.xubo.maven.test.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.034 s [INFO] Finished at: 2016-05-09T18:08:00+08:00 [INFO] Final Memory: 13M/162M [INFO] ------------------------------------------------------------------------
第一次测试需要下载不少依赖包
3.package:
mvn package
生成:
maven_ch2-0.0.1-SNAPSHOT.jar
package后项目的包不会在本地,需要进行install
mvn install
这个时候可以在本地的repository找到相对应的jar包和pom.xml文件以及更新记录等
方法2:没有成功
mvn archetype:generate -DgroupId=org.xubo.maven.Learning - DartifactId=maven_ch3 Dversion=0.0.1-SNAPSHOT
参考:
【1】 http://www.cnblogs.com/buhaiqing/archive/2012/11/04/2754187.html
【2】 http://blog.csdn.net/zgmzyr/article/details/6931957
时间: 2024-10-02 20:09:51