Maven2入门--超级简单
2010-08-11 14:19
176 查看
maven2
能做什么?
maven
可以帮我们更好的管理软件,包括编译,文档生成,管理项目依赖等。
用
maven
来替代
ant
j2ee
下
ant
早已是事实上的标准。但是,每次开发一个新的项目,总要从头写
ant
的
buildfile
(当然,大多数情况直接
copy
旧的
buildfile
)。用
maven
则可省去很多步骤,因为它知道该怎么编译项目。
看看
maven
怎么开始一个新
java
项目:
1.
创建一个项目模板,其中
groupId
是程序的
package
,
artifactId
是项目的名字。这里假定你的项目的
package
是
tutorial,
名称是
tutorial
:
> mvn archetype:create -DgroupId=tutorial -DartifactId=tutorial
2.
现在,看看生成了什么:
> tree /f /a
3.
好了,编译模板程序看看
(
直接打包成
jar
文件
)
:
> cd tutorial
> mvn install
4.
运行看看:
> java -cp target/tutorial-1.0-SNAPSHOT.jar tutorial.App
不需要写复杂的
ant buildfile
,简单的命令,省了许多麻烦。
能做什么?
maven
可以帮我们更好的管理软件,包括编译,文档生成,管理项目依赖等。
用
maven
来替代
ant
j2ee
下
ant
早已是事实上的标准。但是,每次开发一个新的项目,总要从头写
ant
的
buildfile
(当然,大多数情况直接
copy
旧的
buildfile
)。用
maven
则可省去很多步骤,因为它知道该怎么编译项目。
看看
maven
怎么开始一个新
java
项目:
1.
创建一个项目模板,其中
groupId
是程序的
package
,
artifactId
是项目的名字。这里假定你的项目的
package
是
tutorial,
名称是
tutorial
:
> mvn archetype:create -DgroupId=tutorial -DartifactId=tutorial
[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: velocimacro.messages.on => 'false'. [INFO] Setting property: resource.loader => 'classpath'. [INFO] Setting property: resource.manager.logwhenfound => 'false'. [INFO] ************************************************************** [INFO] Starting Jakarta Velocity v1.4 [INFO] RuntimeInstance initializing. [INFO] Default Properties File: org/apache/velocity/runtime/defaults/velocity.properties [INFO] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl) [INFO] Resource Loader Instantiated: org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader [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 'VM_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 global in scope if allowed. [INFO] Velocimacro : initialization complete. [INFO] Velocity successfully started. [INFO] [archetype:create] [INFO] Defaulting package to group ID: tutorial [INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking for updates from central [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating Archetype: maven-archetype-quickstart:RELEASE [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: tutorial [INFO] Parameter: packageName, Value: tutorial [INFO] Parameter: package, Value: tutorial [INFO] Parameter: artifactId, Value: tutorial [INFO] Parameter: basedir, Value: G:/tmp [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] ********************* End of debug info from resources from generated POM *********************** |
现在,看看生成了什么:
> tree /f /a
G:. /---tutorial | pom.xml | /---src +---main | /---java | /---tutorial | App.java | /---test /---java /---tutorial AppTest.java |
好了,编译模板程序看看
(
直接打包成
jar
文件
)
:
> cd tutorial
> mvn install
[INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building tutorial [INFO] task-segment: [install] [INFO] ------------------------------------------------------------------------ [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to G:/tmp/tutorial/target/classes [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] [INFO] Compiling 1 source file to G:/tmp/tutorial/target/test-classes [INFO] [surefire:test] [INFO] Surefire report directory: G:/tmp/tutorial/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running tutorial.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.078 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [jar:jar] [INFO] Building jar: G:/tmp/tutorial/target/tutorial-1.0-SNAPSHOT.jar [INFO] [install:install] [INFO] Installing G:/tmp/tutorial/target/tutorial-1.0-SNAPSHOT.jar to C:/Documents and Settings/guest/.m2/repository/tutorial/tutorial/1.0-SNAPSHOT/tutorial-1.0-SNAPSHOT.j [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ |
运行看看:
> java -cp target/tutorial-1.0-SNAPSHOT.jar tutorial.App
Hello World! |
ant buildfile
,简单的命令,省了许多麻烦。
相关文章推荐
- springmvc入门--超级简单
- 超级简单的单元测试JUnit4入门实例
- 推荐使用的超级简单paddlepaddle机器学习入门
- 3分钟4个步骤超级简单入门配置lamp
- Nginx超级简单入门
- android AIDL 入门,最最简单的例子
- CMMI简单入门
- Mybatis简单的入门之增删改查
- Python程序员,手把手入门一个简单的Python系统,没有不会的
- MATLAB简单入门一
- 【Java基础】Java注解简单入门
- CKplayer 新手入门超简单使用教程
- 用JS获取地址栏参数的方法(超级简单)
- 机器学习原来如此有趣!全世界最简单的机器学习入门指南
- Shiro MyBatis简单使用(入门)
- hdu-5246(超级赛亚ACMer)(简单贪心)------2015年百度之星程序设计大赛 - 初赛(1)
- ARM NEON 编程简单入门1
- mybatis简单的入门开发步骤
- 超级简单的Android Studio jni 实现(无需命令行)
- struts2简单入门示例