Monday, 5 November 2012

Maven 构建JAVA编写系统的自动化工具

介绍:
Maven is an attempt to apply patterns to a project's build infrastructure.Maven is essentially a project management and comprehension tool and as such provides a way to help with managing:Builds : generate class, jar, war etc file
Documentation: generate javadoc, site documentations etc
Reporting: generate junit text reports.
Dependencies: generate document that describe the package dependencies of the software.
SCM (Software Configuration Management): software setup, version control, log/bug managements etc
Releases: generate releases distribution package
Distribution: web application based distribution settings
安装Maven:


POM文件的设置参考:
POM essentials:
  • project This is the top-level element in all Maven pom.xml files.
  • modelVersion This element indicates what version of the object model this POM is using. The version of the model itself changes very infrequently but it is mandatory in order to ensure stability of use if and when the Maven developers deem it necessary to change the model.
  • groupId This element indicates the unique identifier of the organization or group that created the project. The groupId is one of the key identifiers of a project and is typically based on the fully qualified domain name of your organization. For example org.apache.maven.plugins is the designated groupId for all Maven plug-ins.
  • artifactId This element indicates the unique base name of the primary artifact being generated by this project. The primary artifact for a project is typically a JAR file. Secondary artifacts like source bundles also use the artifactId as part of their final name. A typical artifact produced by Maven would have the form <artifactId>-<version>.<extension> (for example, myapp-1.0.jar).
  • packaging This element indicates the package type to be used by this artifact (e.g. JAR, WAR, EAR, etc.). This not only means if the artifact produced is JAR, WAR, or EAR but can also indicate a specific lifecycle to use as part of the build process. (The lifecycle is a topic we will deal with further on in the guide. For now, just keep in mind that the indicated packaging of a project can play a part in customizing the build lifecycle.) The default value for the packaging element is JAR so you do not have to specify this for most projects.
  • version This element indicates the version of the artifact generated by the project. Maven goes a long way to help you with version management and you will often see the SNAPSHOT designator in a version, which indicates that a project is in a state of development. We will discuss the use of snapshots and how they work further on in this guide.
  • name This element indicates the display name used for the project. This is often used in Maven's generated documentation.
  • url This element indicates where the project's site can be found. This is often used in Maven's generated documentation.
  • description This element provides a basic description of your project. This is often used in Maven's generated documentation.



settings文件的设置参考:


Maven常用命令:
Check for maven version:
     mvn --version

Build the Project: 
     mvn package

Cleans up artifacts created by prior builds
      mvn clean

Generates site documentation for this project
     mvn site

Compile your application sources:
     mvn compile

Compile your test  sources and run your unit tests
     mvn test

Compile your test sources (but not execute the tests)
     mvn test-compile

Create a JAR file
     mvn package

Install the artifact you have generated (the jar file)
     mvn install

Generate an IntelliJ IDEA descriptor for the project
     mvn idea:idea

Using Eclipse IDE
     mvn eclipse:eclipse

No comments:

Post a Comment