Maven让项目管理更轻松(一)待续1.Maven概述 当您的项目逐渐变得庞大和复杂时,最好使用一种构建工具来自动
Maven让项目管理更轻松(一)待续
1.Maven概述
当您的项目逐渐变得庞大和复杂时,最好使用一种构建工具来自动构建您的项目。例如,一个典型的java项目,每次构建时都要经历编译java源代码,把class文件打成.jar包,生成javadocs文档等步骤。这些步骤都可以用构建工具帮您自动完成。说到构建工具,大家肯定都知道make,但make是依赖具体操作系统的。Java-centric选择了Ant,一种可以跨平台的使用xml来替换Makefile糟糕语法的构建工具。
来自Apache软件组织的构建工具Maven更可能成为您的选择,Maven不仅提供了out-of-the-box的解决方案来统一处理构建相关的任务,还提供了信息统计的功能。使您的开发团队可以更好地跟踪项目的进展情况。
Maven具有以下功能:
(1)产生Javadoc文档
(2) 运行unit测试
(3) 源代码文法分析
(4) 产生违反团队编码规范的详细报告
(5) 产生CVS最新提交报告
(6) 产生CVS更改最频繁的文件报告和提交最频繁的开发人员报告
(7)产生可以交叉引用的HTML格式的源代码,等等。
2.Maven软件下载
Maven软件下载可以到http://maven.apache.org/download.html
笔者使用的为 Maven 2.0.4
3.Maven软件配置
1。创建d:\project目录,将已下载的Maven软件解压到project目录下
2。设置MAVEN_HOME=D:\project\maven-2.0.4
3。设置path 在path中加入 ;%MAVEN_HOME%\bin
运行m2.bat mvn.bat出现以下提示则表明设置成功了!
[INFO] Scanning for projects...
[INFO] ------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------
[INFO] You must specify at least one goal. Try 'install'
[INFO] ------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Thu Apr 13 17:43:37 CST 2006
[INFO] Final Memory: 1M/2M
[INFO] ------------------------------------
4。设置 Local Repository(此处和2.0.4以前的版本有所不同)
找到D:\project\maven-2.0.4\conf下的settings.xml文件
在<settings>后加入 <localRepository>c:\project</localRepository>
即可
5.设置server
在conf下的settings.xml加入
<server> <id>deploymentRepo</id> <username>repouser</username> <password>repopwd</password> </server> <server> <id>siteServer</id> <privateKey>c:\project\server</privateKey> <passphrase>optional; leave empty if not used.</passphrase> </server>
4.实施操作
(1)运行
进入command,运行下面命令:mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app出现以下信息
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] -------------------------------------
---
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:create] (aggregator-style)
[INFO] -------------------------------------
---
[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.mycompany.app
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.mycompany.app
[INFO] Parameter: outputDirectory, Value: D:\project\my-app
[INFO] Parameter: packageName, Value: com.mycompany.app
[INFO] Parameter: package, Value: com.mycompany.app
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: artifactId, Value: my-app
[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: D:\project\my-app
[INFO] ------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------
[INFO] Total time: 6 seconds
[INFO] Finished at: Thu Apr 13 18:11:15 CST 2006
[INFO] Final Memory: 4M/7M
[INFO] ------------------------------------
则表示运行完成。。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/tanbo/archive/2006/04/13/662117.aspx
更多资料:
1. http://www.ibm.com/developerworks/cn/java/j-maven/