﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-破破烂烂的盘子-文章分类-Maven</title><link>http://www.blogjava.net/lvdougao/category/6729.html</link><description>水狐</description><language>zh-cn</language><lastBuildDate>Thu, 01 Mar 2007 12:15:01 GMT</lastBuildDate><pubDate>Thu, 01 Mar 2007 12:15:01 GMT</pubDate><ttl>60</ttl><item><title>Maven 试用手记----开始一个新的项目并编译和测试</title><link>http://www.blogjava.net/lvdougao/articles/26827.html</link><dc:creator>水狐</dc:creator><author>水狐</author><pubDate>Fri, 06 Jan 2006 01:39:00 GMT</pubDate><guid>http://www.blogjava.net/lvdougao/articles/26827.html</guid><wfw:comment>http://www.blogjava.net/lvdougao/comments/26827.html</wfw:comment><comments>http://www.blogjava.net/lvdougao/articles/26827.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/lvdougao/comments/commentRss/26827.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lvdougao/services/trackbacks/26827.html</trackback:ping><description><![CDATA[<P><FONT size=4><STRONG><EM>开始一个新的项目并编译和测试<BR><BR></EM></STRONG></FONT><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这里将要创建第一个Maven项目。我们将要用到的是Maven的原型机制（archetype mechanism）原型被定义为一个在所有其他性质相同的事物的原始式样或模型（archetype is defined as an original pattern or model from which all other things of the same kind are made）在Maven中，一个原型是一个已经被使用者按需剪裁组合的Maven项目模板，下面我们就来看一下Maven的原型机制是如何工作的。</FONT></P>
<P><FONT size=2><STRONG>&nbsp;<FONT color=#800080>ps:如果想了解什么是Archetypes请访问：</FONT></STRONG><BR><EM>&nbsp;</EM></FONT><A href="http://maven.apache.org/guides/introduction/introduction-to-archetypes.html"><FONT size=2><EM>http://maven.apache.org/guides/introduction/introduction-to-archetypes.html</EM></FONT></A></P>
<P><FONT size=2>下面来建立一个最简单的项目、执行下面的语句：</FONT></P>
<P><FONT color=#a52a2a size=2>mvn archetype:create -DgroupId=com.maventest.pro -DartifactId=my</FONT></P>
<P><FONT size=2>执行上面的语句之前请保证你已经联入Internet<BR>C:\&gt;<FONT color=#a52a2a>md MavenTest<BR></FONT>C:\&gt;<FONT color=#a52a2a>cd MavenTest<BR><FONT color=#000000>C:\MavenTest&gt;</FONT>mvn archetype:create -DgroupId=com.maventest.pro -DartifactId=my<BR><FONT color=#000000>[INFO] Scanning for projects...<BR>[INFO] Searching repository for plugin with prefix: 'archetype'.<BR>[INFO] org.codehaus.mojo: checking for updates from central<BR>[INFO] artifact org.apache.maven.plugins:maven-archetype-plugin: checking for up<BR>dates from central<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-archet"><FONT color=#000000>http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-archet</FONT></A><BR><FONT color=#000000>ype-plugin/1.0-alpha-3/maven-archetype-plugin-1.0-alpha-3.pom<BR>1K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugin"><FONT color=#000000>http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugin</FONT></A><BR><FONT color=#000000>-parent/2.0-beta-1/maven-plugin-parent-2.0-beta-1.pom<BR>6K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-archet"><FONT color=#000000>http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-archet</FONT></A><BR><FONT color=#000000>ype-plugin/1.0-alpha-3/maven-archetype-plugin-1.0-alpha-3.jar<BR>6K downloaded<BR>[INFO] -------------------------------------------------------------------------<BR>---<BR>[INFO] Building Maven Default Project<BR>[INFO]&nbsp;&nbsp;&nbsp; task-segment: [archetype:create] (aggregator-style)<BR>[INFO] -------------------------------------------------------------------------<BR>---<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/org/apache/maven/maven-archetype-core"><FONT color=#000000>http://repo1.maven.org/maven2/org/apache/maven/maven-archetype-core</FONT></A><BR><FONT color=#000000>/1.0-alpha-3/maven-archetype-core-1.0-alpha-3.pom<BR>1K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/org/apache/maven/maven-archetype/1.0"><FONT color=#000000>http://repo1.maven.org/maven2/org/apache/maven/maven-archetype/1.0</FONT></A><FONT color=#000000>-<BR>alpha-3/maven-archetype-1.0-alpha-3.pom<BR>638b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/org/apache/maven/maven/2.0-beta-1/mav"><FONT color=#000000>http://repo1.maven.org/maven2/org/apache/maven/maven/2.0-beta-1/mav</FONT></A><BR><FONT color=#000000>en-2.0-beta-1.pom<BR>6K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/plexus/plexus-utils/1.0.3/plexus-util"><FONT color=#000000>http://repo1.maven.org/maven2/plexus/plexus-utils/1.0.3/plexus-util</FONT></A><BR><FONT color=#000000>s-1.0.3.pom<BR>970b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/plexus/plexus-root/1.0.3/plexus-root"><FONT color=#000000>http://repo1.maven.org/maven2/plexus/plexus-root/1.0.3/plexus-root</FONT></A><FONT color=#000000>-<BR>1.0.3.pom<BR>5K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/plexus/plexus-container-default/1.0-a"><FONT color=#000000>http://repo1.maven.org/maven2/plexus/plexus-container-default/1.0-a</FONT></A><BR><FONT color=#000000>lpha-6/plexus-container-default-1.0-alpha-6.pom<BR>916b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/plexus/plexus-containers/1.0.2/plexus"><FONT color=#000000>http://repo1.maven.org/maven2/plexus/plexus-containers/1.0.2/plexus</FONT></A><BR><FONT color=#000000>-containers-1.0.2.pom<BR>471b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/classworlds/classworlds/1.1-alpha-2/c"><FONT color=#000000>http://repo1.maven.org/maven2/classworlds/classworlds/1.1-alpha-2/c</FONT></A><BR><FONT color=#000000>lassworlds-1.1-alpha-2.pom<BR>3K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/junit/junit/3.8.1/junit-3.8.1.pom"><FONT color=#000000>http://repo1.maven.org/maven2/junit/junit/3.8.1/junit-3.8.1.pom</FONT></A><BR><FONT color=#000000>145b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/plexus/plexus-utils/1.0.2/plexus-util"><FONT color=#000000>http://repo1.maven.org/maven2/plexus/plexus-utils/1.0.2/plexus-util</FONT></A><BR><FONT color=#000000>s-1.0.2.pom<BR>740b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/org/apache/maven/maven-model/2.0-beta"><FONT color=#000000>http://repo1.maven.org/maven2/org/apache/maven/maven-model/2.0-beta</FONT></A><BR><FONT color=#000000>-1/maven-model-2.0-beta-1.pom<BR>1K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/plexus/plexus-velocity/1.0/plexus-vel"><FONT color=#000000>http://repo1.maven.org/maven2/plexus/plexus-velocity/1.0/plexus-vel</FONT></A><BR><FONT color=#000000>ocity-1.0.pom<BR>943b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/plexus/plexus-components/1.0/plexus-c"><FONT color=#000000>http://repo1.maven.org/maven2/plexus/plexus-components/1.0/plexus-c</FONT></A><BR><FONT color=#000000>omponents-1.0.pom<BR>1K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/plexus/plexus-root/1.0/plexus-root-1"><FONT color=#000000>http://repo1.maven.org/maven2/plexus/plexus-root/1.0/plexus-root-1</FONT></A><FONT color=#000000>.<BR>0.pom<BR>4K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/commons-logging/commons-logging/1.0.2"><FONT color=#000000>http://repo1.maven.org/maven2/commons-logging/commons-logging/1.0.2</FONT></A><BR><FONT color=#000000>/commons-logging-1.0.2.pom<BR>810b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/commons-collections/commons-collectio"><FONT color=#000000>http://repo1.maven.org/maven2/commons-collections/commons-collectio</FONT></A><BR><FONT color=#000000>ns/2.0/commons-collections-2.0.pom<BR>171b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/velocity/velocity/1.4/velocity-1.4.po"><FONT color=#000000>http://repo1.maven.org/maven2/velocity/velocity/1.4/velocity-1.4.po</FONT></A><BR><FONT color=#000000>m<BR>2K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/velocity/velocity-dep/1.4/velocity-de"><FONT color=#000000>http://repo1.maven.org/maven2/velocity/velocity-dep/1.4/velocity-de</FONT></A><BR><FONT color=#000000>p-1.4.pom<BR>1K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/log4j/log4j/1.2.8/log4j-1.2.8.pom"><FONT color=#000000>http://repo1.maven.org/maven2/log4j/log4j/1.2.8/log4j-1.2.8.pom</FONT></A><BR><FONT color=#000000>145b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/plexus/plexus-container-default/1.0-a"><FONT color=#000000>http://repo1.maven.org/maven2/plexus/plexus-container-default/1.0-a</FONT></A><BR><FONT color=#000000>lpha-2/plexus-container-default-1.0-alpha-2.pom<BR>170b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/org/apache/maven/maven-artifact/2.0-b"><FONT color=#000000>http://repo1.maven.org/maven2/org/apache/maven/maven-artifact/2.0-b</FONT></A><BR><FONT color=#000000>eta-1/maven-artifact-2.0-beta-1.pom<BR>711b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/org/apache/maven/maven-plugin-api/2.0"><FONT color=#000000>http://repo1.maven.org/maven2/org/apache/maven/maven-plugin-api/2.0</FONT></A><BR><FONT color=#000000>-beta-1/maven-plugin-api-2.0-beta-1.pom<BR>615b downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/commons-logging/commons-logging/1.0.2"><FONT color=#000000>http://repo1.maven.org/maven2/commons-logging/commons-logging/1.0.2</FONT></A><BR><FONT color=#000000>/commons-logging-1.0.2.jar<BR>25K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/org/apache/maven/maven-archetype-core"><FONT color=#000000>http://repo1.maven.org/maven2/org/apache/maven/maven-archetype-core</FONT></A><BR><FONT color=#000000>/1.0-alpha-3/maven-archetype-core-1.0-alpha-3.jar<BR>14K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/plexus/plexus-velocity/1.0/plexus-velocity-1.0.jar"><FONT color=#000000>http://repo1.maven.org/maven2/plexus/plexus-velocity/1.0/plexus-velocity-1.0.jar</FONT></A><BR><FONT color=#000000>4K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/velocity/velocity-dep/1.4/velocity-dep-1.4.jar"><FONT color=#000000>http://repo1.maven.org/maven2/velocity/velocity-dep/1.4/velocity-dep-1.4.jar</FONT></A><BR><FONT color=#000000>505K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/velocity/velocity/1.4/velocity-1.4.jar"><FONT color=#000000>http://repo1.maven.org/maven2/velocity/velocity/1.4/velocity-1.4.jar</FONT></A><BR><FONT color=#000000>352K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/commons-collections/commons-collectio"><FONT color=#000000>http://repo1.maven.org/maven2/commons-collections/commons-collectio</FONT></A><BR><FONT color=#000000>ns/2.0/commons-collections-2.0.jar<BR>88K downloaded<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/log4j/log4j/1.2.8/log4j-1.2.8.jar"><FONT color=#000000>http://repo1.maven.org/maven2/log4j/log4j/1.2.8/log4j-1.2.8.jar</FONT></A><BR></FONT><FONT color=#000000>344K downloaded<BR>[INFO] Setting property: classpath.resource.loader.class =&gt; 'org.codehaus.plexus<BR>.velocity.ContextClassLoaderResourceLoader'.<BR>[INFO] Setting property: resource.loader =&gt; 'classpath'.<BR>[INFO] **************************************************************<BR>[INFO] Starting Jakarta Velocity v1.4<BR>[INFO] RuntimeInstance initializing.<BR>[INFO] Default Properties File: org\apache\velocity\runtime\defaults\velocity.pr<BR>operties<BR>[INFO] Default ResourceManager initializing. (class org.apache.velocity.runtime.<BR>resource.ResourceManagerImpl)<BR>[INFO] Resource Loader Instantiated: org.codehaus.plexus.velocity.ContextClassLo<BR>aderResourceLoader<BR>[INFO] ClasspathResourceLoader : initialization starting.<BR>[INFO] ClasspathResourceLoader : initialization complete.<BR>[INFO] ResourceCache : initialized. (class org.apache.velocity.runtime.resource.<BR>ResourceCacheImpl)<BR>[INFO] Default ResourceManager initialization complete.<BR>[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Literal<BR>[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Macro<BR>[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Parse<BR>[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Include<BR>[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach<BR>[INFO] Created: 20 parsers.<BR>[INFO] Velocimacro : initialization starting.<BR>[INFO] Velocimacro : adding VMs from VM library template : VM_global_library.vm<BR>[ERROR] ResourceManager : unable to find resource 'VM_global_library.vm' in any<BR>resource loader.<BR>[INFO] Velocimacro : error using&nbsp; VM library template VM_global_library.vm : org<BR>.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'V<BR>M_global_library.vm'<BR>[INFO] Velocimacro :&nbsp; VM library template macro registration complete.<BR>[INFO] Velocimacro : allowInline = true : VMs can be defined inline in templates</FONT></FONT></P>
<P><FONT size=2><FONT color=#000000>[INFO] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT<BR>replace previous VM definitions<BR>[INFO] Velocimacro : allowInlineLocal = false : VMs defined inline will be&nbsp; glob<BR>al in scope if allowed.<BR>[INFO] Velocimacro : messages on&nbsp; : VM system will output logging messages<BR>[INFO] Velocimacro : autoload off&nbsp; : VM system will not automatically reload glo<BR>bal library macros<BR>[INFO] Velocimacro : initialization complete.<BR>[INFO] Velocity successfully started.<BR>[INFO] [archetype:create]<BR>[INFO] Defaulting package to group ID: com.maventest.pro<BR>[INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking<BR>&nbsp;for updates from central<BR>Downloading: </FONT><A href="http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-arc"><FONT color=#000000>http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-arc</FONT></A><BR><FONT color=#000000>hetype-quickstart/1.0-alpha-3/maven-archetype-quickstart-1.0-alpha-3.jar<BR>5K downloaded<BR>[INFO] ----------------------------------------------------------------------------<BR>[INFO] Using following parameters for creating Archetype: maven-archetype-quicks<BR>tart:RELEASE<BR>[INFO] ----------------------------------------------------------------------------<BR>[INFO] Parameter: groupId, Value: com.maventest.pro<BR>[INFO] Parameter: outputDirectory, Value: C:\MavenTest\my<BR>[INFO] Parameter: packageName, Value: com.maventest.pro<BR>[INFO] Parameter: package, Value: com.maventest.pro<BR>[INFO] Parameter: version, Value: 1.0-SNAPSHOT<BR>[INFO] Parameter: artifactId, Value: my<BR>[INFO] ResourceManager : found archetype-resources/pom.xml with loader org.codeh<BR>aus.plexus.velocity.ContextClassLoaderResourceLoader<BR>[INFO] ********************* End of debug info from resources from generated POM<BR>&nbsp;***********************<BR>[INFO] ResourceManager : found archetype-resources/src/main/java/App.java with l<BR>oader org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader<BR>[INFO] ResourceManager : found archetype-resources/src/test/java/AppTest.java wi<BR>th loader org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader<BR>[INFO] Archetype created in dir: C:\MavenTest\my<BR>[INFO] ----------------------------------------------------------------------------<BR>[INFO] BUILD SUCCESSFUL<BR>[INFO] ----------------------------------------------------------------------------<BR>[INFO] Total time: 4 minutes 39 seconds<BR>[INFO] Finished at: Fri Jan 06 07:29:27 CST 2006<BR>[INFO] Final Memory: 4M/7M<BR>[INFO] ----------------------------------------------------------------------------<BR>C:\MavenTest&gt;<BR><BR>&nbsp;&nbsp;&nbsp; 一旦你执行后、会注意到发生了几件事情<BR>1、在MavenTest目录下出现了一个名为my的新项目工程。而且里面包含一个名字为pom.xml<BR>的文件。pom.xml和src是同级目录。<BR><FONT color=#800080>my<BR>|-- pom.xml<BR>`-- src<BR>&nbsp;&nbsp;&nbsp; |-- main<BR>&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp; `-- java<BR>&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `-- com<BR>&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `-- maventest<BR>&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `-- pro<BR>&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `-- App.java<BR>&nbsp;&nbsp;&nbsp; `-- test<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `-- java<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `-- com<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `-- maventest<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `-- pro<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `-- AppTest.java<BR><BR><FONT color=#000000>这个pom.xml文件内容如下：<BR>&lt;project xmlns="</FONT><A href="http://maven.apache.org/POM/4.0.0"><FONT color=#000000>http://maven.apache.org/POM/4.0.0</FONT></A><FONT color=#000000>" <BR>xmlns:xsi="</FONT><A href="http://www.w3.org/2001/XMLSchema-instance"><FONT color=#000000>http://www.w3.org/2001/XMLSchema-instance</FONT></A><FONT color=#000000>"<BR>&nbsp; xsi:schemaLocation="</FONT><A href="http://maven.apache.org/POM/4.0.0"><FONT color=#000000>http://maven.apache.org/POM/4.0.0</FONT></A><FONT color=#000000> <BR></FONT><A href="http://maven.apache.org/maven-v4_0_0.xsd"><FONT color=#000000>http://maven.apache.org/maven-v4_0_0.xsd</FONT></A></FONT></FONT><FONT color=#000000>"&gt;<BR>&nbsp; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;<BR>&nbsp; &lt;groupId&gt;com.maventest.pro&lt;/groupId&gt;<BR>&nbsp; &lt;artifactId&gt;my&lt;/artifactId&gt;<BR>&nbsp; &lt;packaging&gt;jar&lt;/packaging&gt;<BR>&nbsp; &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;<BR>&nbsp; &lt;name&gt;Maven Quick Start Archetype&lt;/name&gt;<BR>&nbsp; &lt;url&gt;http://maven.apache.org&lt;/url&gt;<BR>&nbsp; &lt;dependencies&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;dependency&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;junit&lt;/groupId&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;junit&lt;/artifactId&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;3.8.1&lt;/version&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;scope&gt;test&lt;/scope&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;/dependency&gt;<BR>&nbsp; &lt;/dependencies&gt;<BR>&lt;/project&gt;<BR><BR>这里我们看到两个目录分别为应用程序源和测试源，这是个标准的Maven项目布局。而这个结构布局通常都是手工创建的。</FONT></FONT></P>
<P><FONT size=2><FONT color=#000000><FONT color=#800080><FONT color=#000000>[faq]<BR>Q：什么是POM？<BR>A：Project Object Model 项目对象模型、Maven的基本单元。详细了解访问：<BR></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A href="http://maven.apache.org/guides/introduction/introduction-to-the-pom.html">http://maven.apache.org/guides/introduction/introduction-to-the-pom.html</A><BR></FONT><BR>2、就是Maven在首次运行的时候要连接Internet获取相关的文件。<BR><BR><STRONG>pom.xml文件中的标签元素说明</STRONG>：<BR><BR><STRONG>·project</STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这是所有pom.xml的顶层<BR><STRONG>·modelVersion</STRONG>&nbsp;&nbsp;&nbsp;这个元素指出POM现在使用的对象模型版本，除非开发者强制性的为了<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;确保稳定性而进行的必要改变、一般都是不发生变化的。<BR><STRONG>·groupId</STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这个就是指出被被创建项目的唯一标识、通常使用域名。<BR><STRONG>·artifactId</STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这个元素指出了生成项目时的唯一主要的的名字、通常这个名字被作为<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Jar的名字。<BR><STRONG>·packaging</STRONG> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 打包类型 (e.g. JAR, WAR, EAR, etc.). 这个不仅仅意味着打包的产品类型<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 也指出了一个建造过程中的详细生命周期。<BR><STRONG>·version</STRONG> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这个元素指出在项目被生成的时候的版本，通常你所看到的<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SNAPSHOT指的是开发进行的状态<BR><STRONG>·name</STRONG> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;这个元素指出项目相识的名字、通常被用在Maven生成的文档中<BR><STRONG>·url</STRONG> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这个元素指出在哪里可以找到这个项目的站点、通常也被用到Maven的<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 文档中。<BR><STRONG>·description</STRONG> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这个元素为你的项目提供一个基本的描述，通常被用在Maven生成的文<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;档中。<BR><BR><STRONG>下面我们就项目进行测试和编译</STRONG><BR><EM><STRONG><FONT color=#000000 size=3>编译</FONT></STRONG></EM>：<BR>&nbsp;执行：&nbsp; </FONT><FONT color=#a52a2a>mvn compile</FONT></FONT></P>
<P><FONT size=2><FONT color=#000000>C:\MavenTest\my&gt;<FONT color=#a52a2a>mvn compile</FONT><BR>[INFO] Scanning for projects...<BR>[INFO] ----------------------------------------------------------------------------<BR>[INFO] Building Maven Quick Start Archetype<BR>[INFO]&nbsp;&nbsp;&nbsp; task-segment: [compile]<BR>[INFO] ----------------------------------------------------------------------------<BR>[INFO] [resources:resources]<BR>[INFO] Using default encoding to copy filtered resources.<BR>[INFO] [compiler:compile]<BR>[INFO] Nothing to compile - all classes are up to date<BR>[INFO] ----------------------------------------------------------------------------<BR>[INFO] BUILD SUCCESSFUL<BR>[INFO] ----------------------------------------------------------------------------<BR>[INFO] Total time: 1 second<BR>[INFO] Finished at: Fri Jan 06 09:08:13 CST 2006<BR>[INFO] Final Memory: 2M/5M<BR>[INFO] ----------------------------------------------------------------------------<BR>[INFO] Total time: 4 minutes 39 seconds&nbsp; <BR>[INFO] Finished at: Fri Jan 06 07:29:27 CST 2006<BR>[INFO] Final Memory: 4M/7M&nbsp;&nbsp; <BR>[INFO] ---------------------------------------------------------------------------<BR><BR><STRONG><EM><FONT size=3>测试</FONT></EM></STRONG>：<BR>&nbsp;执行： </FONT><FONT color=#a52a2a>mvn test</FONT></FONT></P>
<P><FONT size=2><FONT color=#000000>C:\MavenTest\my&gt;<FONT color=#a52a2a>mvn test</FONT><BR>[INFO] Scanning for projects...<BR>[INFO] ----------------------------------------------------------------------------<BR>[INFO] Building Maven Quick Start Archetype<BR>[INFO]&nbsp;&nbsp;&nbsp; task-segment: [test]<BR>[INFO] ----------------------------------------------------------------------------<BR>[INFO] [resources:resources]<BR>[INFO] Using default encoding to copy filtered resources.<BR>[INFO] [compiler:compile]<BR>[INFO] Nothing to compile - all classes are up to date<BR>[INFO] [resources:testResources]<BR>[INFO] Using default encoding to copy filtered resources.<BR>[INFO] [compiler:testCompile]<BR>[INFO] Nothing to compile - all classes are up to date<BR>[INFO] [surefire:test]<BR>[INFO] Setting reports dir: C:\MavenTest\my\target/surefire-reports</FONT></FONT></P>
<P><FONT size=2><FONT color=#000000>-------------------------------------------------------<BR>&nbsp;T E S T S<BR>-------------------------------------------------------<BR>[surefire] Running com.maventest.pro.AppTest<BR>[surefire] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.015 sec</FONT></FONT></P>
<P><FONT size=2><FONT color=#000000>Results :<BR>[surefire] Tests run: 1, Failures: 0, Errors: 0</FONT></FONT></P>
<P><FONT size=2><FONT color=#000000>[INFO] ----------------------------------------------------------------------------<BR>[INFO] BUILD SUCCESSFUL<BR>[INFO] ----------------------------------------------------------------------------<BR>[INFO] Total time: 2 seconds<BR>[INFO] Finished at: Fri Jan 06 09:07:45 CST 2006<BR>[INFO] Final Memory: 3M/6M<BR>[INFO] ----------------------------------------------------------------------------</FONT></FONT></P>
<P><FONT size=2><FONT color=#000000>这个时候观察一下my 下的目录结构。会发现生成了target 目录，这个就是Maven对程序进行编译和测试而生成的目标文件夹。</FONT></FONT></P>
<P><FONT size=2><FONT color=#000000>请注意这里compile和test是分别对两个类进行编译的。compile是对App.java进行编译，而test是对AppTest.java进行编译和测试。<BR>如果单单是想编译AppTest.java的话可以使用下面的命令：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT color=#a52a2a>mvn test-compile<BR><BR><BR><BR></FONT><FONT color=#800080>后面我讲下如何在eclipse导入Maven构建的项目，待续…………<BR><BR>前篇：<A HREF="/lvdougao/articles/26814.html">Maven 安装</A></FONT></P></FONT></FONT><img src ="http://www.blogjava.net/lvdougao/aggbug/26827.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lvdougao/" target="_blank">水狐</a> 2006-01-06 09:39 <a href="http://www.blogjava.net/lvdougao/articles/26827.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Maven 试用手记----安装</title><link>http://www.blogjava.net/lvdougao/articles/26814.html</link><dc:creator>水狐</dc:creator><author>水狐</author><pubDate>Thu, 05 Jan 2006 22:48:00 GMT</pubDate><guid>http://www.blogjava.net/lvdougao/articles/26814.html</guid><wfw:comment>http://www.blogjava.net/lvdougao/comments/26814.html</wfw:comment><comments>http://www.blogjava.net/lvdougao/articles/26814.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lvdougao/comments/commentRss/26814.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lvdougao/services/trackbacks/26814.html</trackback:ping><description><![CDATA[<P><FONT size=4><STRONG><EM>Maven 安装<BR></EM></STRONG></FONT><FONT size=2>准备工作<BR>1、Maven 2 下载&nbsp; </FONT><A href="http://maven.apache.org/download.html"><FONT size=2>http://maven.apache.org/download.html</FONT></A><BR><BR><FONT size=2>我下载的是maven-2.0-bin.zip 解压缩出来 按照官方的Document 配置JDK和Maven的环境变量：<BR>Unzip maven-2.0.1-bin.zip to the directory you wish to install Maven 2.0<BR>"Environment Variables" button, then editing the PATH variable in the user variables. eg. "C:\Program Files\Apache Software Foundation\maven-2.0.1\bin";%PATH%<BR>JAVA_HOME , eg. C:\Program Files\Java\jdk1.4.2_06<BR>Run mvn --version to verify that it is correctly installed.</FONT></P>
<P><FONT size=2>然后在DOS下运行<BR>&nbsp;C:\Documents and Settings\Administrator&gt;mvn -version<BR>&nbsp;Maven version: 2.0<BR>显示出版本号是2.0</FONT></P>
<P><FONT size=2>看过《JUnit in Action》的朋友可能会对Maven 1有个了解、当时还是beta版。书中举了个例子，好像是在Automating Junit章节<BR>这里要说下Maven 1。Maven 2 对Maven 1进行了重写。所以Maven 1和Maven 2有许多共同点，但它们还有几个主要的不同之处。你可以通过对两个版本的使用来发现其区别。<BR><BR>到这里Maven就安装完成了，接着、我们开始一个新的项目<BR><BR><FONT color=#800080>后篇：<A HREF="/lvdougao/articles/26827.html"><FONT color=#800080>开始一个新的项目并编译和测试</FONT> </A></FONT></FONT></P><img src ="http://www.blogjava.net/lvdougao/aggbug/26814.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lvdougao/" target="_blank">水狐</a> 2006-01-06 06:48 <a href="http://www.blogjava.net/lvdougao/articles/26814.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>