安装Maven;

配置M2_HOME;

查看版本:mvn -v

官网:

http://maven.apache.org/index.html

http://maven.apache.org/guides/index.html

进入pom.xml所在的目录:

清理:mvn clean

打包:mvn package

打包源码:mvn source:jar

安装:mvn install 打包代码并安装到本地仓库

安装源码:mvn source:jar install 打包代码(源码也会被打包并安装)并安装到本地仓库

清理代码,打包(包含源码)、安装(包含源码)、相关构建时跳过单元测试

mvn clean source:jar install -Dmaven.test.skip=true

发布代码包:mvn deploy


查看插件的帮助文档命令:

mvn help:describe -Dplugin=plugin_name -Dgoal=goal -Ddetail=true

如插件:

<artifactId>maven-source-plugin</artifactId>

插件的名称为source。

详情见官网:http://maven.apache.org/plugins/index.html


一个简单的插件配置:

<build> <plugins> <!-- 是否执行 单元测试用例 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> <!-- 发布项目代码包时,同时发布源码包 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>3.0.1</version> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <!-- 设置项目的编译级别 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins></build>