锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
榪欓噷灝嗚鍒涘緩絎竴涓狹aven欏圭洰銆傛垜浠皢瑕佺敤鍒扮殑鏄疢aven鐨勫師鍨嬫満鍒訛紙archetype mechanism錛夊師鍨嬭瀹氫箟涓轟竴涓湪鎵鏈夊叾浠栨ц川鐩稿悓鐨勪簨鐗╃殑鍘熷寮忔牱鎴栨ā鍨嬶紙archetype is defined as an original pattern or model from which all other things of the same kind are made錛夊湪Maven涓紝涓涓師鍨嬫槸涓涓凡緇忚浣跨敤鑰呮寜闇鍓緇勫悎鐨凪aven欏圭洰妯℃澘錛屼笅闈㈡垜浠氨鏉ョ湅涓涓婱aven鐨勫師鍨嬫満鍒舵槸濡備綍宸ヤ綔鐨勩?/FONT>
ps:濡傛灉鎯充簡瑙d粈涔堟槸Archetypes璇瘋闂細
http://maven.apache.org/guides/introduction/introduction-to-archetypes.html
涓嬮潰鏉ュ緩绔嬩竴涓渶綆鍗曠殑欏圭洰銆佹墽琛屼笅闈㈢殑璇彞錛?/FONT>
mvn archetype:create -DgroupId=com.maventest.pro -DartifactId=my
鎵ц涓婇潰鐨勮鍙ヤ箣鍓嶈淇濊瘉浣犲凡緇忚仈鍏nternet
C:\>md MavenTest
C:\>cd MavenTest
C:\MavenTest>mvn archetype:create -DgroupId=com.maventest.pro -DartifactId=my
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] org.codehaus.mojo: checking for updates from central
[INFO] artifact org.apache.maven.plugins:maven-archetype-plugin: checking for up
dates from central
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-archet
ype-plugin/1.0-alpha-3/maven-archetype-plugin-1.0-alpha-3.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugin
-parent/2.0-beta-1/maven-plugin-parent-2.0-beta-1.pom
6K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-archet
ype-plugin/1.0-alpha-3/maven-archetype-plugin-1.0-alpha-3.jar
6K downloaded
[INFO] -------------------------------------------------------------------------
---
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:create] (aggregator-style)
[INFO] -------------------------------------------------------------------------
---
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-archetype-core
/1.0-alpha-3/maven-archetype-core-1.0-alpha-3.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-archetype/1.0-
alpha-3/maven-archetype-1.0-alpha-3.pom
638b downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven/2.0-beta-1/mav
en-2.0-beta-1.pom
6K downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-utils/1.0.3/plexus-util
s-1.0.3.pom
970b downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-root/1.0.3/plexus-root-
1.0.3.pom
5K downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-container-default/1.0-a
lpha-6/plexus-container-default-1.0-alpha-6.pom
916b downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-containers/1.0.2/plexus
-containers-1.0.2.pom
471b downloaded
Downloading: http://repo1.maven.org/maven2/classworlds/classworlds/1.1-alpha-2/c
lassworlds-1.1-alpha-2.pom
3K downloaded
Downloading: http://repo1.maven.org/maven2/junit/junit/3.8.1/junit-3.8.1.pom
145b downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-utils/1.0.2/plexus-util
s-1.0.2.pom
740b downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-model/2.0-beta
-1/maven-model-2.0-beta-1.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-velocity/1.0/plexus-vel
ocity-1.0.pom
943b downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-components/1.0/plexus-c
omponents-1.0.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-root/1.0/plexus-root-1.
0.pom
4K downloaded
Downloading: http://repo1.maven.org/maven2/commons-logging/commons-logging/1.0.2
/commons-logging-1.0.2.pom
810b downloaded
Downloading: http://repo1.maven.org/maven2/commons-collections/commons-collectio
ns/2.0/commons-collections-2.0.pom
171b downloaded
Downloading: http://repo1.maven.org/maven2/velocity/velocity/1.4/velocity-1.4.po
m
2K downloaded
Downloading: http://repo1.maven.org/maven2/velocity/velocity-dep/1.4/velocity-de
p-1.4.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/log4j/log4j/1.2.8/log4j-1.2.8.pom
145b downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-container-default/1.0-a
lpha-2/plexus-container-default-1.0-alpha-2.pom
170b downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-artifact/2.0-b
eta-1/maven-artifact-2.0-beta-1.pom
711b downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-plugin-api/2.0
-beta-1/maven-plugin-api-2.0-beta-1.pom
615b downloaded
Downloading: http://repo1.maven.org/maven2/commons-logging/commons-logging/1.0.2
/commons-logging-1.0.2.jar
25K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-archetype-core
/1.0-alpha-3/maven-archetype-core-1.0-alpha-3.jar
14K downloaded
Downloading: http://repo1.maven.org/maven2/plexus/plexus-velocity/1.0/plexus-velocity-1.0.jar
4K downloaded
Downloading: http://repo1.maven.org/maven2/velocity/velocity-dep/1.4/velocity-dep-1.4.jar
505K downloaded
Downloading: http://repo1.maven.org/maven2/velocity/velocity/1.4/velocity-1.4.jar
352K downloaded
Downloading: http://repo1.maven.org/maven2/commons-collections/commons-collectio
ns/2.0/commons-collections-2.0.jar
88K downloaded
Downloading: http://repo1.maven.org/maven2/log4j/log4j/1.2.8/log4j-1.2.8.jar
344K downloaded
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus
.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] **************************************************************
[INFO] Starting Jakarta Velocity v1.4
[INFO] RuntimeInstance initializing.
[INFO] Default Properties File: org\apache\velocity\runtime\defaults\velocity.pr
operties
[INFO] Default ResourceManager initializing. (class org.apache.velocity.runtime.
resource.ResourceManagerImpl)
[INFO] Resource Loader Instantiated: org.codehaus.plexus.velocity.ContextClassLo
aderResourceLoader
[INFO] ClasspathResourceLoader : initialization starting.
[INFO] ClasspathResourceLoader : initialization complete.
[INFO] ResourceCache : initialized. (class org.apache.velocity.runtime.resource.
ResourceCacheImpl)
[INFO] Default ResourceManager initialization complete.
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Literal
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Macro
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Parse
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Include
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
[INFO] Created: 20 parsers.
[INFO] Velocimacro : initialization starting.
[INFO] Velocimacro : adding VMs from VM library template : VM_global_library.vm
[ERROR] ResourceManager : unable to find resource 'VM_global_library.vm' in any
resource loader.
[INFO] Velocimacro : error using VM library template VM_global_library.vm : org
.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'V
M_global_library.vm'
[INFO] Velocimacro : VM library template macro registration complete.
[INFO] Velocimacro : allowInline = true : VMs can be defined inline in templates
[INFO] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT
replace previous VM definitions
[INFO] Velocimacro : allowInlineLocal = false : VMs defined inline will be glob
al in scope if allowed.
[INFO] Velocimacro : messages on : VM system will output logging messages
[INFO] Velocimacro : autoload off : VM system will not automatically reload glo
bal library macros
[INFO] Velocimacro : initialization complete.
[INFO] Velocity successfully started.
[INFO] [archetype:create]
[INFO] Defaulting package to group ID: com.maventest.pro
[INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking
for updates from central
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-arc
hetype-quickstart/1.0-alpha-3/maven-archetype-quickstart-1.0-alpha-3.jar
5K downloaded
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating Archetype: maven-archetype-quicks
tart:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.maventest.pro
[INFO] Parameter: outputDirectory, Value: C:\MavenTest\my
[INFO] Parameter: packageName, Value: com.maventest.pro
[INFO] Parameter: package, Value: com.maventest.pro
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: artifactId, Value: my
[INFO] ResourceManager : found archetype-resources/pom.xml with loader org.codeh
aus.plexus.velocity.ContextClassLoaderResourceLoader
[INFO] ********************* End of debug info from resources from generated POM
***********************
[INFO] ResourceManager : found archetype-resources/src/main/java/App.java with l
oader org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader
[INFO] ResourceManager : found archetype-resources/src/test/java/AppTest.java wi
th loader org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader
[INFO] Archetype created in dir: C:\MavenTest\my
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 4 minutes 39 seconds
[INFO] Finished at: Fri Jan 06 07:29:27 CST 2006
[INFO] Final Memory: 4M/7M
[INFO] ----------------------------------------------------------------------------
C:\MavenTest>
涓鏃︿綘鎵ц鍚庛佷細娉ㄦ剰鍒板彂鐢熶簡鍑犱歡浜嬫儏
1銆佸湪MavenTest鐩綍涓嬪嚭鐜頒簡涓涓悕涓簃y鐨勬柊欏圭洰宸ョ▼銆傝屼笖閲岄潰鍖呭惈涓涓悕瀛椾負pom.xml
鐨勬枃浠躲俻om.xml鍜宻rc鏄悓綰х洰褰曘?BR>my
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- com
| `-- maventest
| `-- pro
| `-- App.java
`-- test
`-- java
`-- com
`-- maventest
`-- pro
`-- AppTest.java
榪欎釜pom.xml鏂囦歡鍐呭濡備笅錛?BR><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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maventest.pro</groupId>
<artifactId>my</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
榪欓噷鎴戜滑鐪嬪埌涓や釜鐩綍鍒嗗埆涓哄簲鐢ㄧ▼搴忔簮鍜屾祴璇曟簮錛岃繖鏄釜鏍囧噯鐨凪aven欏圭洰甯冨眬銆傝岃繖涓粨鏋勫竷灞閫氬父閮芥槸鎵嬪伐鍒涘緩鐨勩?/FONT>
[faq]
Q錛氫粈涔堟槸POM錛?BR>A錛歅roject Object Model 欏圭洰瀵硅薄妯″瀷銆丮aven鐨勫熀鏈崟鍏冦傝緇嗕簡瑙h闂細
http://maven.apache.org/guides/introduction/introduction-to-the-pom.html
2銆佸氨鏄疢aven鍦ㄩ嬈¤繍琛岀殑鏃跺欒榪炴帴Internet鑾峰彇鐩稿叧鐨勬枃浠躲?BR>
pom.xml鏂囦歡涓殑鏍囩鍏冪礌璇存槑錛?BR>
路project 榪欐槸鎵鏈塸om.xml鐨勯《灞?BR>路modelVersion 榪欎釜鍏冪礌鎸囧嚭POM鐜板湪浣跨敤鐨勫璞℃ā鍨嬬増鏈紝闄ら潪寮鍙戣呭己鍒舵х殑涓轟簡
紜繚紼沖畾鎬ц岃繘琛岀殑蹇呰鏀瑰彉銆佷竴鑸兘鏄笉鍙戠敓鍙樺寲鐨勩?BR>路groupId 榪欎釜灝辨槸鎸囧嚭琚鍒涘緩欏圭洰鐨勫敮涓鏍囪瘑銆侀氬父浣跨敤鍩熷悕銆?BR>路artifactId 榪欎釜鍏冪礌鎸囧嚭浜嗙敓鎴愰」鐩椂鐨勫敮涓涓昏鐨勭殑鍚嶅瓧銆侀氬父榪欎釜鍚嶅瓧琚綔涓?BR> Jar鐨勫悕瀛椼?BR>路packaging 鎵撳寘綾誨瀷 (e.g. JAR, WAR, EAR, etc.). 榪欎釜涓嶄粎浠呮剰鍛崇潃鎵撳寘鐨勪駭鍝佺被鍨?BR> 涔熸寚鍑轟簡涓涓緩閫犺繃紼嬩腑鐨勮緇嗙敓鍛藉懆鏈熴?BR>路version 榪欎釜鍏冪礌鎸囧嚭鍦ㄩ」鐩鐢熸垚鐨勬椂鍊欑殑鐗堟湰錛岄氬父浣犳墍鐪嬪埌鐨?BR> SNAPSHOT鎸囩殑鏄紑鍙戣繘琛岀殑鐘舵?BR>路name 榪欎釜鍏冪礌鎸囧嚭欏圭洰鐩歌瘑鐨勫悕瀛椼侀氬父琚敤鍦∕aven鐢熸垚鐨勬枃妗d腑
路url 榪欎釜鍏冪礌鎸囧嚭鍦ㄥ摢閲屽彲浠ユ壘鍒拌繖涓」鐩殑绔欑偣銆侀氬父涔熻鐢ㄥ埌Maven鐨?BR> 鏂囨。涓?BR>路description 榪欎釜鍏冪礌涓轟綘鐨勯」鐩彁渚涗竴涓熀鏈殑鎻忚堪錛岄氬父琚敤鍦∕aven鐢熸垚鐨勬枃
妗d腑銆?BR>
涓嬮潰鎴戜滑灝遍」鐩繘琛屾祴璇曞拰緙栬瘧
緙栬瘧錛?BR> 鎵ц錛?nbsp; mvn compile
C:\MavenTest\my>mvn compile
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven Quick Start Archetype
[INFO] task-segment: [compile]
[INFO] ----------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Fri Jan 06 09:08:13 CST 2006
[INFO] Final Memory: 2M/5M
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 4 minutes 39 seconds
[INFO] Finished at: Fri Jan 06 07:29:27 CST 2006
[INFO] Final Memory: 4M/7M
[INFO] ---------------------------------------------------------------------------
嫻嬭瘯錛?BR> 鎵ц錛?mvn test
C:\MavenTest\my>mvn test
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven Quick Start Archetype
[INFO] task-segment: [test]
[INFO] ----------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] Setting reports dir: C:\MavenTest\my\target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
[surefire] Running com.maventest.pro.AppTest
[surefire] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.015 sec
Results :
[surefire] Tests run: 1, Failures: 0, Errors: 0
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Fri Jan 06 09:07:45 CST 2006
[INFO] Final Memory: 3M/6M
[INFO] ----------------------------------------------------------------------------
榪欎釜鏃跺欒瀵熶竴涓媘y 涓嬬殑鐩綍緇撴瀯銆備細鍙戠幇鐢熸垚浜唗arget 鐩綍錛岃繖涓氨鏄疢aven瀵圭▼搴忚繘琛岀紪璇戝拰嫻嬭瘯鑰岀敓鎴愮殑鐩爣鏂囦歡澶廣?/FONT>
璇鋒敞鎰忚繖閲宑ompile鍜宼est鏄垎鍒涓や釜綾昏繘琛岀紪璇戠殑銆俢ompile鏄App.java榪涜緙栬瘧錛岃宼est鏄AppTest.java榪涜緙栬瘧鍜屾祴璇曘?BR>濡傛灉鍗曞崟鏄兂緙栬瘧AppTest.java鐨勮瘽鍙互浣跨敤涓嬮潰鐨勫懡浠わ細
mvn test-compile
鍚庨潰鎴戣涓嬪浣曞湪eclipse瀵煎叆Maven鏋勫緩鐨勯」鐩紝寰呯畫鈥︹︹︹?BR>
鍓嶇瘒錛?A HREF="/lvdougao/articles/26814.html">Maven 瀹夎
鐒跺悗鍦―OS涓嬭繍琛?BR> C:\Documents and Settings\Administrator>mvn -version
Maven version: 2.0
鏄劇ず鍑虹増鏈彿鏄?.0
鐪嬭繃銆奐Unit in Action銆嬬殑鏈嬪弸鍙兘浼氬Maven 1鏈変釜浜嗚В銆佸綋鏃惰繕鏄痓eta鐗堛備功涓婦浜嗕釜渚嬪瓙錛屽ソ鍍忔槸鍦ˋutomating Junit绔犺妭
榪欓噷瑕佽涓婱aven 1銆侻aven 2 瀵筂aven 1榪涜浜嗛噸鍐欍傛墍浠aven 1鍜孧aven 2鏈夎澶氬叡鍚岀偣錛屼絾瀹冧滑榪樻湁鍑犱釜涓昏鐨勪笉鍚屼箣澶勩備綘鍙互閫氳繃瀵逛袱涓増鏈殑浣跨敤鏉ュ彂鐜板叾鍖哄埆銆?BR>
鍒拌繖閲孧aven灝卞畨瑁呭畬鎴愪簡錛屾帴鐫銆佹垜浠紑濮嬩竴涓柊鐨勯」鐩?BR>
鍚庣瘒錛?A HREF="/lvdougao/articles/26827.html">寮濮嬩竴涓柊鐨勯」鐩茍緙栬瘧鍜屾祴璇?/FONT>