1. help插件 P14
该插件可以告诉我们maven使用的模型,以及某个插件有哪些可用的目标。如打印实际的pom文件、settings内容等。P14
常用的目标及描述如下:
help:active-profiles
Description: Displays a list of the profiles which are currently active for this build.
help:effective-pom
Description: Displays the effective POM as an XML for this build, with the active profiles factored in.
help:effective-settings
Description: Displays the calculated settings as XML for this project,given any profile enhancement and the inheritance of the global settings into the user-level settings.
help:describe
Description: Displays a list of the attributes for a Maven Plugin and/or goals (aka Mojo - Maven plain Old Java Object).
如想查看maven-bundle-plugin插件的目标列表:mvn help:describe -Dplugin=bundle
如想查看maven-bundle-plugin插件带有参数的详细的目标列表:mvn help:describe -Dplugin=bundle –Dfull
如想查看maven-bundle-plugin插件的install目标的详细信息:mvn help:describe -Dplugin=bundle -Dmojo=install –Dfull
2. 创建一个简单的maven项目 P20
mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch03 -DartifactId=simple -DpackageName=org.sonatype.mavenbook
编译、测试、打包并安装(在命令行,进入simple目录,然后运行以下命令)mvn install
在target目录中会生成一个jar包:simple-1.0-SNAPSHOT.jar,该jar包的名字是由artifactId+“-”+version构成,如果在pom.xml文件中添加如下配置,则可以生成自定义的文件名:<build>
<finalName>simple-webapp</finalName>
</build>
这样在target目录中会生成一个名叫simple-webapp的jar包:simple-webapp.jar,在命令行运行程序(cp参数用来指定classpath):java -cp target/simple-1.0-SNAPSHOT.jar org.sonatype.mavenbook.App
3. POM:Project Object Model,项目对象模型
pom文件最开始的<groupId>、<artifactId>、<packaging>、<version>四个元素唯一的标识了一个项目,是项目的坐标。P24
4. 不要混淆
mvn archetype:create 这叫执行了一个maven插件的目标(goal)
mvn install 这叫执行了一个maven的生命周期阶段
5. provided范围
当为项目创建JAR文件的时候,它的依赖不会被捆绑在生成的构件中,他们只是用来编译。当用Maven来创建WAR或者EAR,可以配置Maven让它在生成的构件中捆绑依赖,也可以配置Maven,使用provided范围,让它排除WAR文件中特定的依赖。provided范围告诉Maven一个依赖在编译的时候需要,但是它不应该被捆绑在构建的输出中。当开发web应用的时候provided范围变得十分有用,需要通过Servlet API来编译代码,但是不希望Servlet API的JAR文件包含在web应用的WEB-INF/lib目录中。
6. exec插件P53
This plugin has 3 goals:
exec:exec
Description: A Plugin for executing external programs.
Deprecated. No reason given
exec:help
Description: Display help information on exec-maven-plugin. Call
mvn exec:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details.
Deprecated. No reason given
exec:java
Description: Executes the supplied java class in the current VM with the
enclosing project's dependencies as classpath.
Deprecated. No reason given
例如执行某个java程序:mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main
7. 打印出项目的依赖树P53
X:\simple-weather>mvn dependency:tree
X:\simple-weather >set MAVEN_OPTS= -Xms128m -Xmx512m
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Chapter 4 Simple Weather Project
[INFO] task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree]
[INFO] org.sonatype.mavenbook.ch04:simple-weather:jar:1.0
[INFO] +- log4j:log4j:jar:1.2.14:compile
[INFO] +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] +- jaxen:jaxen:jar:1.1.1:compile
[INFO] | +- jdom:jdom:jar:1.0:compile
[INFO] | +- xerces:xercesImpl:jar:2.6.2:compile
[INFO] | \- xom:xom:jar:1.0:compile
[INFO] | +- xerces:xmlParserAPIs:jar:2.6.2:compile
[INFO] | +- xalan:xalan:jar:2.6.0:compile
[INFO] | \- com.ibm.icu:icu4j:jar:2.6.1:compile
[INFO] +- velocity:velocity:jar:1.5:compile
[INFO] | +- commons-collections:commons-collections:jar:3.1:compile
[INFO] | +- commons-lang:commons-lang:jar:2.1:compile
[INFO] | \- oro:oro:jar:2.0.8:compile
[INFO] +- org.apache.commons:commons-io:jar:1.3.2:test
[INFO] \- junit:junit:jar:3.8.1:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Tue Aug 25 15:20:11 CST 2009
[INFO] Final Memory: 12M/127M
[INFO] ------------------------------------------------------------------------
分享到:
相关推荐
Maven权威指南中文版(完整).pdf
Maven是一种构建工具,一种项目管理工具...所有的作者,以及本书后面的公司,Sonatype1,相信本书的出版标志着围绕Maven变革和开发,以及其周围软件生态系统的一个新的阶段的开始。 2008年9月1日英文版 2009年7月中文版
实用maven教程,Maven权威指南_中文完整版清晰,实用maven教程
官方的maven权威指南原版书籍,关于maven使用有困惑的可以看一下,受益匪浅。
Maven权威指南最全讲授,一本好书带你最快学会maven,带你走进最深层次的maven
Maven权威指南中文版.pdf格式,是一本细心编排的入门指南和参考手册。
maven 权威指南(中文版) 。
maven权威指南中文版,
Maven权威指南_中文完整版清晰 Maven权威指南_中文完整版清晰 Maven权威指南_中文完整版清晰
Maven权威指南中文版(完整) 详细讲解maven 资料 pom
上本书中maven权威指南开发实例代码。很详细。
Maven权威指南中文版 Maven权威指南中文版 Maven权威指南中文版Maven权威指南中文版 Maven权威指南中文版
《Maven权威指南》学习笔记
Maven权威指南_中文完整版清晰。。。。。。。。。。。。。
maven权威指南高清版 mvn-examples-1.0.zip MAVEN权威指南对应示例代码