《Maven权威指南》读书笔记(1)

[size=medium][color=red]1. help插件 P14[/color][/size]
[size=small][color=blue]该插件可以告诉我们maven使用的模型,以及某个插件有哪些可用的目标。如打印实际的pom文件、settings内容等。P14
常用的目标及描述如下:[/color][/size]
[code]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).
[/code]
[size=small][color=blue]如想查看maven-bundle-plugin插件的目标列表:[/color][/size][code]mvn help:describe -Dplugin=bundle[/code] [size=small][color=blue]如想查看maven-bundle-plugin插件带有参数的详细的目标列表:[/color][/size][code]mvn help:describe -Dplugin=bundle –Dfull[/code] [size=small][color=blue]如想查看maven-bundle-plugin插件的install目标的详细信息:[/color][/size][code]mvn help:describe -Dplugin=bundle -Dmojo=install –Dfull[/code]
[size=medium][color=red]2. 创建一个简单的maven项目 P20[/color][/size]
[code]mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch03 -DartifactId=simple -DpackageName=org.sonatype.mavenbook[/code] [size=small][color=blue]编译、测试、打包并安装(在命令行,进入simple目录,然后运行以下命令)[/color][/size][code]mvn install[/code] [size=small][color=blue]在target目录中会生成一个jar包:simple-1.0-SNAPSHOT.jar,该jar包的名字是由artifactId+“-”+version构成,如果在pom.xml文件中添加如下配置,则可以生成自定义的文件名:[/color][/size]
<build>
<finalName>simple-webapp</finalName>
</build>
[color=blue]这样在target目录中会生成一个名叫simple-webapp的jar包:simple-webapp.jar,在命令行运行程序(cp参数用来指定classpath):[/color][code]java -cp target/simple-1.0-SNAPSHOT.jar org.sonatype.mavenbook.App[/code]
[size=medium][color=red]3. POM:Project Object Model,项目对象模型[/color][/size]
[color=blue]pom文件最开始的<groupId>、<artifactId>、<packaging>、<version>四个元素唯一的标识了一个项目,是项目的坐标。P24[/color]

[size=medium][color=red]4. 不要混淆[/color][/size]
[color=blue]mvn archetype:create 这叫执行了一个maven插件的目标(goal)
mvn install 这叫执行了一个maven的生命周期阶段
[/color]
[size=medium][color=red]5. provided范围[/color][/size]
[color=blue]当为项目创建JAR文件的时候,它的依赖不会被捆绑在生成的构件中,他们只是用来编译。当用Maven来创建WAR或者EAR,可以配置Maven让它在生成的构件中捆绑依赖,也可以配置Maven,使用provided范围,让它排除WAR文件中特定的依赖。provided范围告诉Maven一个依赖在编译的时候需要,但是它不应该被捆绑在构建的输出中。当开发web应用的时候provided范围变得十分有用,需要通过Servlet API来编译代码,但是不希望Servlet API的JAR文件包含在web应用的WEB-INF/lib目录中。[/color]

[size=medium][color=red]6. exec插件P53[/color][/size]
[code]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
[/code] [color=blue]例如执行某个java程序:[/color][code]mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main[/code]
[size=medium][color=red]7. 打印出项目的依赖树P53[/color][/size]
[code]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] ------------------------------------------------------------------------
[/code]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值