Maven命令总结

1. 打包jar包

mvn clean package

2. 打包可执行jar包

需借助maven-shade-plugin插件,配置如下:

<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.xx.HelloWorld</mainClass>

</transformer>

<transformers>

</configuration>

</execution>

</executions>

</plugin>

3. 使用Archetype生成项目骨架

mvn archetype:generate


4.安装jar包到本地仓库中

mvn clean install


5. 依赖范围

compile: 编绎依赖范围。对于编绎、测试和运行三种classpath有效

     test:测试依赖范围。只对测试classpath有效

provided: 已提供依赖范围。对编绎、测试classpath有效 如servlet-api

runtime:运行时依赖范围。对于测试、运行classpath有效 如jdbc

system:系统依赖范围。 和provided依赖范围一样。但它必须通过systemPath元素显式指定依赖文件的路径。此类依赖不是能过maven仓库解析的,而是通过本地系统绑 定。systemPath元素可以引用环境变量。

<dependency>

<groupId>javax.sql</groupId>

<artifactId>jdbc-stdex</artifactId>

<version>2.0</version>

<scope>system</scope>

<systemPath>${java.home}/lib/rt.jar</systemPath>

依赖范围影响传递性依赖:

 compile testprovided runtime
compile compile -- -- runtime
testtest----test
providedprovided--providedprovided
runtimeruntime----runtime

6. Maven会自动解析所有项目的直接依赖和传递性依赖,并且根据规则正确判断每个依赖的范围,对于一些依赖冲突,也能进行调节,以确保每个构件只有一个版本在依赖中存在。这时得到的依赖称为已解析依赖。查看已解析依赖的命令为:

mvn dependency:list

mvn dependency:tree

mvn dependnecy:analyze

7.Maven有三套独立的生命周期:clean, default,site

clean生命周期的目的为清理项目

default生命周期的目的为构建项目

site生命周期的目的为建立项目站点

clean包含三个阶段:

pre-clean:执行一些清理前需要完成的工作

clean清理上一次构建生成的文件

post-clean执行一些清理后需要完成的工作

default:

validate

initialize

generate-sources

process-sources

generate-resources

process-resources

compile

process-classes

generate-test-sources

process-test-sources

generate-test-resources

process-test-resources

test-compile

process-test-classes

test

prepare-package

package

pre-integration-test

integration-test

post-integration-test

verify

install: 将包安装到maven本地库

deploy:将包复制到远程仓库

site生命周期:

pre-site

site

post-site

site-deploy

8.自定义插件目标绑定

源代码打成jar包

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

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

<version>2.1.1</version>

<executions>

<execution>

<id>attach-sources</id>

<phase>verify</phase>

<goals>

<goal>jar-no-jar</goal>

</goals>

</execution>

</executions>

</plugin>

</plugins>

</build>

9. 查看插件目标的默认绑定阶段

mvn help:describe-Dplugin=org.apache.maven.plugins:maven-source-plugin:2.1.1 -Ddetail


10 插件配置

命令行插件配置

跳过测试  mvn install -Dmaven.test.skip = true

11 使用maven-help-plugin描述插件

如:获取maven-compile-plugin 2.1版本的信息:

mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin:2.1

获取最新版本的表述:

mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin

可以使用前缀替换坐标:

mvn help:describe -Dplugin=compiler

描述插件目标信息:

mvn help:describe -Dplugin=compiler -Dgoal=compile

输出详细信息:

mvn help:describe -Dplugin=compiler -Ddetail

12.在线插件信息

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

下载地址:http://repol.maven.org/maven2/org/apache/maven/plugins/



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值