Maven深入理解

Plugins

Plugin是Maven的核心,所有功能的实现是通过插件完成。Maven提供了很多插件,也有第三方提供。参考:http://maven.apache.org/plugins/index.html,几个比较常用的插件:

  1. Maven Archetype Plugin
  2. Maven Eclipse Plugin
  3. Maven Compiler Plugin
  4. Maven xdoclet Plugin
  5. Maven Source Plugin
  6. Maven Javadoc Plugin
  7. Maven SCM
  8. Maven AntRun Plugin
  9. Maven Dependency Plugin
  10. Maven Release Plugin
  11. Maven Assembly Plugin


Maven Archetype Plugin

Maven Archetype Plugin用来创建maven项目的模板即archetype,也可以从一个项目创建一个archtype,
参考:http://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html

Goals:

archetype:createDeprecated.Please use the generate mojo instead.
archetype:create-from-projectCreates an archetype from the current project.
archetype:generateGenerates a new project from an archetype.
archetype:helpDisplay help information on maven-archetype-plugin. Call
mvn archetype:help -Ddetail=true -Dgoal=
to display parameter details.

Usage:

创建简单的maven项目

mvn archetype:create \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DarchetypeArtifactId=maven-archetype-webapp \
-DgroupId=com.mycompany.app \
-DartifactId=my-webapp

创建简单的webapp项目

mvn archetype:create \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DarchetypeArtifactId=maven-archetype-webapp \
-DgroupId=com.mycompany.app \
-DartifactId=my-webapph4.3.创建复杂的maven项目
mvn archetype:generate -DarchetypeCatalog=internal
通过指定archetypeCatalog参数,从指定的参数中选择需要创建的项目,参数定义见参考。如:
E:\workspaces>mvn archetype:generate -DarchetypeCatalog=internal
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.0-alpha-5:generate (default-cli) @ standalon
e-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.0-alpha-5:generate (default-cli) @ standalon
e-pom <<<
[INFO]
[INFO] — maven-archetype-plugin:2.0-alpha-5:generate (default-cli) @ standalon
e-pom —
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.
archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: internal -> appfuse-basic-jsf (AppFuse archetype for creating a web applicati
on with Hibernate, Spring and JSF)
2: internal -> appfuse-basic-spring (AppFuse archetype for creating a web applic
ation with Hibernate, Spring and Spring MVC)
3: internal -> appfuse-basic-struts (AppFuse archetype for creating a web applic
ation with Hibernate, Spring and Struts 2)
4: internal -> appfuse-basic-tapestry (AppFuse archetype for creating a web appl
ication with Hibernate, Spring and Tapestry 4)
5: internal -> appfuse-core (AppFuse archetype for creating a jar application wi
th Hibernate and Spring and XFire)
6: internal -> appfuse-modular-jsf (AppFuse archetype for creating a modular app
lication with Hibernate, Spring and JSF)
7: internal -> appfuse-modular-spring (AppFuse archetype for creating a modular
application with Hibernate, Spring and Spring MVC)
8: internal -> appfuse-modular-struts (AppFuse archetype for creating a modular
application with Hibernate, Spring and Struts 2)
9: internal -> appfuse-modular-tapestry (AppFuse archetype for creating a modula
r application with Hibernate, Spring and Tapestry 4)
10: internal -> makumba-archetype (Archetype for a simple Makumba application)
11: internal -> maven-archetype-j2ee-simple (A simple J2EE Java application)
12: internal -> maven-archetype-marmalade-mojo (A Maven plugin development proje
ct using marmalade)
13: internal -> maven-archetype-mojo (A Maven Java plugin development project)
14: internal -> maven-archetype-portlet (A simple portlet application)
15: internal -> maven-archetype-profiles ()
16: internal -> maven-archetype-quickstart ()
17: internal -> maven-archetype-site-simple (A simple site generation project)
18: internal -> maven-archetype-site (A more complex site project)
19: internal -> maven-archetype-webapp (A simple Java web application)
20: internal -> data-app (A new Databinder application with sources and resource
s.)
21: internal -> camel-archetype-component (Creates a new Camel component)
22: internal -> camel-archetype-activemq (Creates a new Camel project that confi
gures and interacts with ActiveMQ)
23: internal -> camel-archetype-java (Creates a new Camel project using Java DSL
)
24: internal -> camel-archetype-scala (Creates a new Camel project using Scala D
SL)
25: internal -> camel-archetype-spring (Creates a new Camel project with added S
pring DSL support)
26: internal -> camel-archetype-war (Creates a new Camel project that deploys th
e Camel Web Console, REST API, and your routes as a WAR)
27: internal -> jini-service-archetype (Archetype for Jini service project creat
ion)
28: internal -> jbosscc-seam-archetype (Maven Archetype to generate a Seam Appli
cation- Documentation)
29: internal -> softeu-archetype-seam (JSF+Facelets+Seam Archetype)
30: internal -> softeu-archetype-seam-simple (JSF+Facelets+Seam (no persistence)
Archetype)
31: internal -> softeu-archetype-jsf (JSF+Facelets Archetype)
32: internal -> jpa-maven-archetype (JPA application)
33: internal -> spring-osgi-bundle-archetype (Spring-OSGi archetype)
34: internal -> bamboo-plugin-archetype (Atlassian Bamboo plugin archetype)
35: internal -> confluence-plugin-archetype (Atlassian Confluence plugin archety
pe)
36: internal -> jira-plugin-archetype (Atlassian JIRA plugin archetype)
37: internal -> maven-archetype-har (Hibernate Archive)
38: internal -> maven-archetype-sar (JBoss Service Archive)
39: internal -> wicket-archetype-quickstart (A simple Apache Wicket project)
40: internal -> quickstart (A simple Apache Tapestry 5 Project)
41: internal -> scala-archetype-simple (A simple scala project)
42: internal -> lift-archetype-blank (A blank/empty liftweb project)
43: internal -> lift-archetype-basic (The basic (liftweb) project)
44: internal -> cocoon-22-archetype-block-plain (http://cocoon.apache.org/2.2/ma
ven-plugins/)
45: internal -> cocoon-22-archetype-block (http://cocoon.apache.org/2.2/maven-pl
ugins/)
46: internal -> cocoon-22-archetype-webapp (http://cocoon.apache.org/2.2/maven-p
lugins/)
47: internal -> myfaces-archetype-helloworld (A simple archetype using MyFaces)
48: internal -> myfaces-archetype-helloworld-facelets (A simple archetype using
MyFaces and facelets)
49: internal -> myfaces-archetype-trinidad (A simple archetype using Myfaces and
Trinidad)
50: internal -> myfaces-archetype-jsfcomponents (A simple archetype for create c
ustom JSF components using MyFaces)
51: internal -> gmaven-archetype-basic (Groovy basic archetype)
52: internal -> gmaven-archetype-mojo (Groovy mojo archetype)
53: internal -> struts2-archetype-starter (Struts 2 Starter Archetype)
54: internal -> tynamo-archetype (Creates a CRUD web application based on Tapest
ry 5 and Tynamo, a model-driven Java web framework)
55: internal -> tellurium-junit-archetype (Tellurium JUnit project archetype for
the Tellurium Automated Testing Framework)
56: internal -> tellurium-testng-archetype (Tellurium TestNG project archetype f
or the Tellurium Automated Testing Framework)
57: internal -> scalate-archetype-empty (Generates a Scalate empty web applicati
on)
58: internal -> scalate-archetype-guice (Generates a Scalate Jog web application
)
Choose a number: 16: 2
Define value for property 'groupId': : cn.bidlink
Define value for property 'artifactId': : srpingMVN
Define value for property 'version': 1.0-SNAPSHOT: :
Define value for property 'package': cn.bidlink: : jar
Confirm properties configuration:
groupId: cn.bidlink
artifactId: srpingMVN
version: 1.0-SNAPSHOT
package: jar
Y: : Y
通过指定'groupId','artifactId','version','package'完成项目的创建。

Maven Eclipse Plugin

Maven Eclipse Plugin 用来创建Eclipse的项目文件((*.classpath, *.wtpmodules and the .settings)。
参考:http://maven.apache.org/plugins/maven-eclipse-plugin/index.html

Goals:

eclipse:configure-workspaceis used to add the classpath variable M2_REPO to Eclipse which points to your local repository and optional to configure other workspace features.
eclipse:eclipsegenerates the Eclipse configuration files.
eclipse:cleanis used to delete the files used by the Eclipse IDE.
eclipse:myeclipseGenerates the MyEclipse configuration files.
eclipse:myeclipse-cleanDeletes the config files used by MyEclipse.
eclipse:helpDisplay help information on maven-eclipse-plugin.

Usage:

在Elcipse使用本地的maven资源库,通过如下命令将M2_REPO变量加入到eclipse

mvn eclipse:configure-workspace \
-Declipse.workspace=testworkspace \
-Declipse.workspaceCodeStylesURL=http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-eclipse-plugin/src/optional/eclipse-config/maven-styles.xml
(或者mvn -Declipse.workspace= eclipse:add-maven-repo)
在.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.core.prefs中会创建:
#Fri Nov 12 13:45:10 CST 2010
org.eclipse.jdt.core.classpathVariable.M2_REPO=C\:
Documents and Settings\\Administrator\\.m2
repository
并且将workspaceCodeStylesURL指定的code styles format文件存放在org.eclipse.jdt.ui.prefs中。

创建eclipse项目配置文件,如:.projectand .classpath files 等

2.1 Load Coding Styles into Workspace
mvn eclipse:eclipse -Declipse.projectDir=. \
-Declipse.workspaceCodeStyleURL=http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-eclipse-plugin/src/optional/eclipse-config/maven-styles.xml
或者在pom.xml中配置

org.apache.maven.plugins
maven-eclipse-plugin
2.8

${basedir}
http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-eclipse-plugin/src/optional/eclipse-config/maven-styles.xml


2.2 Configure Checkstyle

org.apache.maven.plugins
maven-eclipse-plugin
2.8


com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder


com.atlassw.tools.eclipse.checkstyle.CheckstyleNature



.checkstyle








]]>






2.3 Multpile Module Project
2.3.1 垂直的工程结构

  1. 在eclipse中设置MO_REPO classpath变量
  2. 打开window命令窗口,进入workspace目录
  3. 通过命令创建一个maven父工程

mvn archetype:create -DgroupId=cn.bidlink -DartifactId=myproject

  1. 删除src目录,修改pom.xml文件中的packaing为pom:pom
  2. 在父工程下创建多个maven子工程

cd myproject
mvn archetype:create -DgroupId=cn.bidlink -DartifactId=myproject-site
mvn archetype:create -DgroupId=cn.bidlink.core -DartifactId=myproject-core
mvn archetype:create
-DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp
-DgroupId=cn.bidlink -DartifactId=myproject-webapp

  1. 父工程自动将子工程添加在自己的pom.xml中:


myproject-site
myproject-core
myproject-webapp

  1. 子工程的pom中自动继承父工程:


cn.bidlink
myproject
1.0-SNAPSHOT

  1. 子工程之间的依赖,将core子工程添加到myproject-webapp中


cn.bidlink.core
myproject-core
1.0-SNAPSHOT

  1. 创建eclipse项目工程

mvn install
mvn eclipse:eclipse

  1. 在eclispe通过import导入myproject,将会在eclipse创建myproject-webapp,module,site等三个工程,且module中自动会应用core工程。


2.3.2扁平的工程结构

  1. 在myproject中创建一个新目录parent,将myproject下的pom.xml文件移到该目录下
  2. 修改pom.xml文件的子工程


../myproject-site
../myproject-core ../myproject-webapp

  1. 修改子工程pom.xml中的parent引用


myproject
cn.bidlink
1.0-SNAPSHOT
../parent/pom.xml

注意:扁平的工程结构有很多maven plguin 如:release插件不支持。
2.4 Help
通过运行mvn eclipse:help -Ddetail=true -Dgoal=可以获取goal的参数的详细信息。

Maven Compiler Plugin

Maven compiler plugin用来对maven工程源代码进行编译,默认是采用javac,source 和target均采用java1.5版本。
参考:http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html

Goals:

compiler:compileCompiles application sources
compiler:helpDisplay help information on maven-compiler-plugin. Call
mvn compiler:help -Ddetail=true -Dgoal=
to display parameter details.

Usage:

更改java版本和指定javac路径


org.apache.maven.plugins
mavencompilerplugin
2.3.2

1.6
1.6
UTF-8
true
true
${JAVA_HOME}/bin/javac


Maven xdoclet Plugin

Xodoclet plugin用来创建hibernate的pojo对应的mapping文件
参考:http://xdoclet.codehaus.org/Maven2+Plugin
http://www.samaxes.com/2006/07/using-maven-2-xdoclet-2-and-hibernate-3/
Goals:xdoclet
Usage:
配置如下:

xdoclet
maven2-xdoclet2-plugin
2.0.5


xdoclet
generate-sources

xdoclet





xdoclet-plugins
xdocletpluginhibernate
1.0.2


nanocontainer
nanocontainer
1.0-beta-3


xdoclet
xdoclet
2.0.4


generama
generama
1.2.1


freemarker
freemarker




picocontainer
picocontainer
1.0


nanocontainer
nanocontainer-ant
1.0-beta-3


generama
qdox
20051211.114207


commons-jelly
commons-jelly
1.0


commons-jelly
commons-jelly-tags-define
1.0


commons-jelly
commons-jelly-tags-xml
20050823.222913


commons-jexl
commons-jexl
1.0


commons-jelly
commons-jelly-tags-jsl
1.0


saxpath
saxpath
1.0-FCS


jaxen
jaxen
1.1-beta-4







org.xdoclet.plugin.hibernate.HibernateMappingPlugin

3.0
true
${project.build.outputDirectory}



cn/bidlink/*/model/.java




Maven Source Plugin

Maven source plugin 用来对代码源文件进行打包,打包后的source代码可以发布到资源库,在jar包被用到时可以一同被下载到本地,在eclipse工具中可以方便查看源代码。
参考:http://maven.apache.org/plugins/maven-source-plugin/jar-mojo.html

Goals:

source:aggregateAggregate sources for all modules in an aggregator project.
source:jarThis plugin bundles all the sources into a jar archive.
source:helpDisplay help information on maven-source-plugin. Call
mvn source:help -Ddetail=true -Dgoal=
to display parameter details.

Usage:

1.指定输出路径及文件名称




org.apache.maven.plugins
maven-source-plugin
2.1.2

/absolute/path/to/the/output/directory
filename-of-generated-jar-file
false




Maven Javadoc Plugin

Javadoc plugin通过使用javadoc工具给工程创建javadocs
参考:http://maven.apache.org/plugins/maven-javadoc-plugin/

Goals:

  1. javadoc:javadocgenerates the Javadoc files for the project. It executes the standard Javadoc tool and supports the parameters used by the tool.
  2. javadoc:test-javadocgenerates the test Javadoc files for the project. It executes the standard Javadoc tool and supports the parameters used by the tool.
  3. javadoc:aggregategenerates the Javadoc files for an aggregator project. It executes the standard Javadoc tool and supports the parameters used by the tool.
  4. javadoc:test-aggregategenerates the test Javadoc files for an aggregator project. It executes the standard Javadoc tool and supports the parameters used by the tool.
  5. javadoc:jarcreates an archive file of the generated Javadocs. It is used during the release process to create the Javadoc artifact for the project's release. This artifact is uploaded to the remote repository along with the project's compiled binary and source archive.
  6. javadoc:test-jarcreates an archive file of the generated Test Javadocs.
  7. javadoc:aggregate-jarcreates an archive file of the generated Javadocs for an aggregator project.
  8. javadoc:test-aggregate-jarcreates an archive file of the generated Test Javadocs for an aggregator project.
  9. javadoc:fixis an interactive goal which fixes the Javadoc documentation and tags for the Java files.
  10. javadoc:test-fixis an interactive goal which fixes the Javadoc documentation and tags for the test Java files.

Usage:

对多个项目工程创建javadoc


org.apache.maven.plugins
maven-javadoc-plugin
2.7


...



aggregate

aggregate

site


...


...


或者

org.apache.maven.plugins
maven-javadoc-plugin
2.7


...



non-aggregate


...


javadoc



aggregate


...


aggregate


...




Maven SCM Plugin

SCM(Source Control Manager)plugin是maven提供的可以结合版本控制工具(CVS,SVN等)使用的插件。

Goals:

  1. scm:branch- branch the project
  2. scm:validate- validate the scm information in the pom
  3. scm:add- command to add file
  4. scm:unedit- command to stop editing the working copy
  5. scm:export- command to get a fresh exported copy
  6. scm:bootstrap- command to checkout and build a project
  7. scm:changelog- command to show the source code revisions
  8. scm:list- command for get the list of project files
  9. scm:checkin- command for commiting changes
  10. scm:checkout- command for getting the source code
  11. scm:status- command for showing the scm status of the working copy
  12. scm:update- command for updating the working copy with the latest changes
  13. scm:diff- command for showing the difference of the working copy with the remote one
  14. scm:update-subprojects- command for updating all projects in a multi project build
  15. scm:edit- command for starting edit on the working copy
  16. scm:tag- command for tagging a certain revision
  17. scm:helpDisplay help information on maven-scm-plugin. Call
  18. mvn scm:help -Ddetail=true -Dgoal=
  19. to display parameter details.

Usage:

1.配置 SCM


scm:cvs:pserver:@192.168.0.249:/cvsroot/EOSS:base

配置scm链接后,可以在插件中引用

org.apache.maven.plugins
maven-scm-plugin
1.4

developerConnection
install
liangbingyan
654321

cvs_native



配置好cvs,username,password等后可以通过执行scm的相关目标命令。如:
mvn scm:bootstrap 从cvs下载代码并执行install操作

scm的命令应用

2.1显示cvs提交修改记录
mvn -DstartDate=YYYY-MM-DD -DendDate=YYYY-MM-DD scm:changelog
2.2显示不同修改版本之间的不同
mvn -DstartRevision= -DendRevision= scm:diff
2.3打tag标记
mvn -Dtag="" scm:tag
2.4验证scm配置的正确
mvn -DscmConnection="" -DscmDeveloperConnection="" scm:validate
2.5通过命令执行bootstrap,对部署项目很方便
mvn -DconnectionUrl=scm:cvs:sspi:@9bb5e6546229466:2401:/repository:guide-ide-eclipse -Dmaven.scm.provider.cvs.implementation=cvs_native -Dpassword=1q2w3e -Dbasedir=. -DcheckoutDirectory=guide-ide-eclipse -Dgoals=install -DgoalsDirectory=parent scm:bootstrap

Maven AntRun Plugin

Antrun plugin提供了执行ant中的task的功能,可以将ant的task放在pom中。

Goals:

antrun:helpDisplay help information on maven-antrun-plugin. Call
mvn antrun:help -Ddetail=true -Dgoal=
to display parameter details.
antrun:runMaven AntRun Mojo. This plugin provides the capability of calling Ant tasks from a POM by running the nested ant tasks inside the parameter. It is encouraged to move the actual tasks to a separate build.xml file and call that file with an task.

Usage:

1.在pom中使用ant的task


org.apache.maven.plugins
maven-antrun-plugin
1.6


compile
compile













run



推荐将ant的task单独放在一个build.xml文件中,通过如下方式使用:

org.apache.maven.plugins
maven-antrun-plugin
1.6


compile
compile












run




其中build.xml定义如下:








使用自定义的task


"log4j.log4j.jar.path" value="${log4j:log4j:jar}" />
"net/sf/antcontrib/antcontrib.properties">

"for" classname="net.sf.antcontrib.logic.For">

"${log4jproperties}" delimiter="," param="propertykey">

"propertyvalue" from="@{propertykey}" override="true"/>
"src/main/resources/log4j.properties">
"@{propertykey}" value="${propertyvalue}"/>

@{propertykey}=${propertyvalue}



Maven Dependency Plugin

Dependency Plugin提供了对项目依赖的artifacts的操作管理。

Goals:

  1. dependency:copytakes a list of artifacts defined in the plugin configuration section and copies them to a specified location, renaming them or stripping the version if desired. This goal can resolve the artifacts from remote repositories if they don't exist in local.
  2. dependency:copy-dependenciestakes the list of project direct dependencies and optionally transitive dependencies and copies them to a specified location, stripping the version if desired. This goal can also be run from the command line.
  3. dependency:unpacklike copy but unpacks.
  4. dependency:unpack-dependencieslike copy-dependencies but unpacks.
  5. dependency:resolvetells Maven to resolve all dependencies and displays the version.
  6. dependency:listis an alias for dependency:resolve
  7. dependency:sourcestells Maven to resolve all dependencies and their source attachments, and displays the version.
  8. dependency:resolve-pluginsTells Maven to resolve plugins and their dependencies.
  9. dependency:listalias for resolve that lists the dependencies for this project.
  10. dependency:go-offlinetells Maven to resolve everything this project is dependent on (dependencies, plugins, reports) in preparation for going offline.
  11. dependency:purge-local-repositorytells Maven to clear all dependency-artifact files out of the local repository, and optionally re-resolve them.
  12. dependency:build-classpathtells Maven to output the path of the dependencies from the local repository in a classpath format to be used in java -cp. The classpath file may also be attached and installed/deployed along with the main artifact.
  13. dependency:analyzeanalyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused and declared.
  14. dependency:analyze-onlyis the same as analyze, but is meant to be bound in a pom. It does not fork the build and execute test-compile.
  15. dependency:analyze-dep-mgtanalyzes your projects dependencies and lists mismatches between resolved dependencies and those listed in your dependencyManagement section.
  16. dependency:treedisplays the dependency tree for this project.


Usage:

使用依赖关系的tree结构解决依赖冲突

mvn dependency:tree -Dverbose -Dincludes=commons-collections
将看到
[INFO] [dependency:tree]
[INFO] org.apache.maven.plugins:maven-dependency-plugin:maven-plugin:2.0-alpha-5-SNAPSHOT
[INFO] +- org.apache.maven.reporting:maven-reporting-impl:jar:2.0.4:compile
[INFO] | - commons-validator:commons-validator:jar:1.2.0:compile
[INFO] | - commons-digester:commons-digester:jar:1.6:compile
[INFO] | - (commons-collections:commons-collections:jar:2.1:compile - omitted for conflict with 2.0)
[INFO] - org.apache.maven.doxia:doxia-site-renderer:jar:1.0-alpha-8:compile
[INFO] - org.codehaus.plexus:plexus-velocity:jar:1.1.3:compile
[INFO] - commons-collections:commons-collections:jar:2.0:compile
可以很清楚看到相关冲突信息

Maven Assembly Plugin

Assembly 插件提供了手动对某些文件和依赖打成各种包格式的功能。

Goals:

assembly:helpDisplay help information on maven-assembly-plugin. Call
mvn assembly:help -Ddetail=true -Dgoal=
assembly:singleAssemble an application bundle or distribution from an assembly descriptor. This goal is suitable either for binding to the lifecycle or calling directly from the command line (provided all required files are available before the build starts, or are produced by another goal specified before this one on the command line).

Usage:

打web service客户端包
  1. 创建assembly配置文件,如:src/main/assembly/space-ws-jar.xml

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>space-ws-jarid>
<includeBaseDirectory>falseincludeBaseDirectory>
<formats>
<format>jarformat>
formats>
<fileSets>
<fileSet>
<outputDirectory>/outputDirectory>
<directory>
${project.build.outputDirectory}
directory>
<includes>
<include>cn/bidlink/space/webservice/*.classinclude>
<include>cn/bidlink/space/follower/dto/*.classinclude>
<include>cn/bidlink/space/myspace/dto/*.classinclude>
<include>cn/bidlink/space/notice/dto/*.classinclude>
includes>
fileSet>
fileSets>
assembly>

  1. 配置Assembly 插件

<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-assembly-pluginartifactId>
<version>2.2.1version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/space-ws-jar.xmldescriptor>
descriptors>
<appendAssemblyId>falseappendAssemblyId>
<finalName>${space.ws.name}finalName>
configuration>
<executions>
<execution>
<id>make-space-ws-jarid>
<goals>
<goal>singlegoal>
goals>
execution>
executions>
plugin>
3)运行命令:mvn assembly:single就可以将制定文件达成jar包了。

mvn命令使用说明

usage: mvn [options] [] []
Options:
am,-also-make If project list is specified, also
build projects required by the
list
amd,-also-make-dependents If project list is specified, also
build projects that depend on
projects on the list
B,-batch-mode Run in non-interactive (batch)
mode
C,-strict-checksums Fail the build if checksums don't
match
c,-lax-checksums Warn if checksums don't match
cpu,-check-plugin-updates Ineffective, only kept for
backward compatibility
D,-define Define a system property
e,-errors Produce execution error messages
emp,-encrypt-master-password Encrypt master security password
ep,-encrypt-password Encrypt server password
f,-file Force the use of an alternate POM
file.
fae,-fail-at-end Only fail the build afterwards;
allow all non-impacted builds to
continue
ff,-fail-fast Stop at first failure in
reactorized builds
fn,-fail-never NEVER fail the build, regardless
of project result
gs,-global-settings Alternate path for the global
settings file
h,-help Display help information
l,-log-file Log file to where all build output
will go.
N,-non-recursive Do not recurse into sub-projects
npr,-no-plugin-registry Ineffective, only kept for
backward compatibility
npu,-no-plugin-updates Ineffective, only kept for
backward compatibility
nsu,-no-snapshot-updates Supress SNAPSHOT updates
o,-offline Work offline
P,-activate-profiles Comma-delimited list of profiles
to activate
pl,-projects Build specified reactor projects
instead of all projects. A project
can be specified by
[groupId]:artifactId or by its
relative path.
q,-quiet Quiet output - only show errors
rf,-resume-from Resume reactor from specified
project
s,-settings Alternate path for the user
settings file
T,-threads Thread count, for instance 2.0C
where C is core multiplied
t,-toolchains Alternate path for the user
toolchains file
U,-update-snapshots Forces a check for updated
releases and snapshots on remote
repositories
up,-update-plugins Ineffective, only kept for
backward compatibility
V,-show-version Display version information
WITHOUT stopping build
v,-version Display version information
X,-debug Produce execution debug output

例1:

分析eoss-base的dependency,打开debug信息,并且输出到log.txt文件中
E:\workspaces\eossmvn\eoss-core>mvn dependency:tree -Dverbose -Dincludes=eoss-ba
se -X -l log.txt

例2:

使用线下编译方式,不从远程资源库下载包
mvn -o compile

你可能感兴趣的:(maven,maven,javadoc,dependencies,application,eclipse,hibernate)