<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wangsy</groupId>
<artifactId>testMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>testMaven</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
解析:
groupId定义了项目属于哪个组,这个组往往和项目所在的组织或公司存在关联。
artifactId定义了当前Maven项目在组中唯一的ID。
version指定了版本。SNAPSHOT指快照,说明该项目还处于开发中,是不稳定的版本。
mvn clean compile
mvn clean test
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
mvn clean package
mvn clean install
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.
resource.ManifestResourceTransformer">
<mainClass>
com.wangsy.testMaven.App
</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
java –jar target/testMaven-0.0.1-SNAPSHOT.jar
如果是Maven3,简单地运行:
mvn archetype:generate
如果是Maven2,最好运行如下命令:
mvn org.apache.maven.plugins:
maven-archetype-plugin:2.0-alpha-5:generate
会看到一段长长的输出,有很多可用的Archetype供选择,包括著名的Appfuse项目的Archetype,JPA项目的 Archetype等。每一个Archetype前面都会对应有一个编号,同时命令行会提示一个默认的编号,其对应的Archetype为maven-archetype-quickstart,直接加车以选择该Archetype,紧接着Maven会提示输入 要创建项目的groupId、artifactId、version以及包名package。如下图所示:
Archetype会迅速构建起项目的骨架。