2 Star 1 Fork 0

zhrun8899 / learning-notes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
maven.md 18.61 KB
一键复制 编辑 原始数据 按行查看 历史
zhrun8899 提交于 2018-12-25 11:44 . add some new file

maven 修改多模块项目版本

1.pom中增加plugin

<build>

<plugins>

<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>versions-maven-plugin</artifactId>
				<version>2.3</version>
				<configuration>
					<generateBackupPoms>false</generateBackupPoms>
				</configuration>
</plugin>

</plugins>

</build>

2.命令修改

mvn versions -DnewVersion=1.0.1.snapshot

则父子模块中的版本都修改为 1.0.1.snapshot

3.命令更新子模块:在父项目目录下执行:

mvn -N versions:update-child-mod

则子模块的版本号均修改为父项目的版本号

maven 执行特定的测试类 mvn test -Dtest=com.webimation.boss.simpletest.CapitalTest test 察看项目所用的插件====

mvn dependency:resolve-plugins

命令行下载jar源码 mvn org.apache.maven.plugins:maven-dependency-plugin:2.6:get -Dartifact=commons-lang:commons-lang:2.3:jar:sources 配置pom下载源码,并在项目的maven dependencies中能看到 ​ ​ commons-lang ​ commons-lang ​ sources ​ 2.3 ​ 了解maven插件作用 mvn help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-dependency-plugin 较简单的命令 mvn help:describe -Dplugin=org.apache.maven.plugins:maven-war-plugin 或 mvn war:help

各插件详述

1.mvn war:help

war:exploded Description: Create an exploded webapp in a specified directory. war:help Description: Display help information on maven-war-plugin. ​ Call mvn war:help -Ddetail=true -Dgoal= to display parameter ​ details. war:inplace Description: Generate the webapp in the WAR source directory. war:war Description: Build a WAR file.

2.mvn dependency:help

dependency:analyze

Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused and declared. This goal is intended to be used standalone, thus it always executes the test-compile phase - use the dependency:analyze-only goal instead when participating in the build lifecycle. By default, maven-dependency-analyzer is used to perform the analysis, with limitations due to the fact that it works at bytecode level, but any analyzer can be plugged in through analyzer parameter.

dependency:analyze-dep-mgt

This mojo looks at the dependencies after final resolution and looks for mismatches in your dependencyManagement section. In versions of maven prior to 2.0.6, it was possible to inherit versions that didn't match your dependencyManagement. See MNG-1577 for more info. This mojo is also useful for just detecting projects that override the dependencyManagement directly. Set ignoreDirect to false to detect these otherwise normal conditions.

dependency:analyze-duplicate

Analyzes the and tags in the pom.xml and determines the duplicate declared dependencies.

dependency:analyze-only

Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused and declared. This goal is intended to be used in the build lifecycle, thus it assumes that the test-compile phase has been executed - use the dependency:analyze goal instead when running standalone. By default, maven-dependency-analyzer is used to perform the analysis, with limitations due to the fact that it works at bytecode level, but any analyzer can be plugged in through analyzer parameter.

dependency:analyze-report

Analyzes the dependencies of this project and produces a report that summarizes which are: used and declared; used and undeclared; unused and declared.

dependency:build-classpath

This goal will output a classpath string of dependencies from the local repository to a file or log.

dependency:copy

Goal that copies a list of artifacts from the repository to defined locations.

dependency:copy-dependencies

Goal that copies the project dependencies from the repository to a defined location.

dependency:get

Downloads a single artifact transitively from the specified remote repositories. Caveat: will always check the central repository defined in the super pom. You could use a mirror entry in your settings.xml

dependency:go-offline

Goal that resolves all project dependencies, including plugins and reports and their dependencies.

dependency:help

Display help information on maven-dependency-plugin. Call mvn dependency:help -Ddetail=true -Dgoal= to display parameter details.

dependency:list

Displays the list of dependencies for this project.

dependency:list-repositories

Goal that resolves all project dependencies and then lists the repositories used by the build and by the transitive dependencies

dependency:properties

Goal that sets a property pointing to the artifact file for each project dependency. For each dependency (direct and transitive) a project property will be set which follows the groupId:artifactId:type:[classifier] form and contains the path to the resolved artifact.

dependency:purge-local-repository

Remove the project dependencies from the local repository, and optionally re-resolve them.

dependency:resolve

Goal that resolves the project dependencies from the repository.

dependency:resolve-plugins

Goal that resolves all project plugins and reports and their dependencies.

dependency:sources

Goal that resolves the project source dependencies from the repository.

dependency:tree

Displays the dependency tree for this project.

dependency:unpack

Goal that retrieves a list of artifacts from the repository and unpacks them in a defined location.

dependency:unpack-dependencies

Goal that unpacks the project dependencies from the repository to a defined location.

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

在一个稍大一点的组织或团队中,你无法保证所有成员都熟悉Maven,那他们做一些比较愚蠢的事情就会变得很正常,例如给项目引入了外部的 SNAPSHOT依赖而导致构建不稳定,使用了一个与大家不一致的Maven版本而经常抱怨构建出现诡异问题。maven-enforcer- plugin能够帮助你避免之类问题,它允许你创建一系列规则强制大家遵守,包括设定Java版本、设定Maven版本、禁止某些依赖、禁止 SNAPSHOT依赖。只要在一个父POM配置规则,然后让大家继承,当规则遭到破坏的时候,Maven就会报错。除了标准的规则之外,你还可以扩展该插 件,编写自己的规则。maven-enforcer-plugin的enforce目标负责检查规则,它默认绑定到生命周期的validate阶段。 mvn enforcer:display-info mvn enforcer:enforce mvn enforcer:help

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

assembly:help

Description: Display help information on maven-assembly-plugin. ​ Call mvn assembly:help -Ddetail=true -Dgoal= to display ​ parameter details.

assembly:single

Description: Assemble 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).

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

archetype:jar Description: Build a JAR from the current Archetype project.

archetype:update-local-catalog archetype:integration-test archetype:generate archetype:create-from-project archetype:crawl 6.mvn versions:help 7.mvn exec:help 8.mvn jetty:help

9.build-helper-maven-plugin

http://mojo.codehaus.org/build-helper-maven-plugin/

Maven默认只允许指定一个主Java代码目录和一个测试Java代码目录,虽然这其实是个应当尽量遵守的约定,但偶尔你还是会希望能够指定多个 源码目录(例如为了应对遗留项目),build-helper-maven-plugin的add-source目标就是服务于这个目的,通常它被绑定到 默认生命周期的generate-sources阶段以添加额外的源码目录。需要强调的是,这种做法还是不推荐的,因为它破坏了 Maven的约定,而且可能会遇到其他严格遵守约定的插件工具无法正确识别额外的源码目录。

build-helper-maven-plugin的另一个非常有用的目标是attach-artifact,使用该目标你可以以classifier的形式选取部分项目文件生成附属构件,并同时install到本地仓库,也可以deploy到远程仓库。 10.maven-surefire-plugin

http://maven.apache.org/plugins/maven-surefire-plugin/

可能是由于历史的原因,Maven 2/3中用于执行测试的插件不是maven-test-plugin,而是maven-surefire-plugin。其实大部分时间内,只要你的测试 类遵循通用的命令约定(以Test结尾、以TestCase结尾、或者以Test开头),就几乎不用知晓该插件的存在。然而在当你想要跳过测试、排除某些 测试类、或者使用一些TestNG特性的时候,了解maven-surefire-plugin的一些配置选项就很有用了。例如 mvn test -Dtest=FooTest 这样一条命令的效果是仅运行FooTest测试类,这是通过控制maven-surefire-plugin的test参数实现的。

======================== mortbay.jetty :旧的jetty,新版本是org.eclipse.jetty 依赖如下: ​ ​ org.eclipse.jetty.aggregate ​ jetty-all-server ​ 7.6.19.v20160209 ​ ​ ​ ​ org.eclipse.jetty ​ jetty-jsp ​ 7.6.19.v20160209

说明:数据源中使用的是spring-mybatis-merBoss中配置的数据源,mybatis-config.xml中配置的数据源并未使用.仅仅作示范. java -jar mybatis-generator-core-1.3.2.jar -configfile H:\worktemp\mybatisTest\src\main\resources\generator.xml -overwrite 结果:生成bean,dao(有人喜欢称为mapper),及map文件

Jackson fasterxml和codehaus的区别 (fasterxml vs. codehaus) 他们是Jackson的两大分支、也是两个版本的不同包名。Jackson从2.0开始改用新的包名fasterxml;1.x版本的包名是codehaus。除了包名不同,他们的Maven artifact id也不同。1.x版本现在只提供bug-fix,而2.x版本还在不断开发和发布中。如果是新项目,建议直接用2x,

即fasterxml jackson。

=======================================20160512============================================== 在使用mvn package进行编译、打包时,Maven会执行src/test/java中的JUnit测试用例,有时为了跳过测试,会使用参数-DskipTests和-Dmaven.test.skip=true,这两个参数的主要区别是: -DskipTests,不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下。

-Dmaven.test.skip=true,不执行测试用例,也不编译测试用例类。

aven 安装外部包: mvn install:install-file -Dfile=jta-1_0_1B-classes.zip -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=F:/JAR Pack/ojdbc14.jar

cd d:\mposlib mvn install:install-file -DgroupId=com.tangdi.production -Dversion=1.0-release -DartifactId=mpbean -Dpackaging=jar -Dfile=mpbean-1.0-release.jar mvn install:install-file -DgroupId=com.tangdi.production -Dversion=1.0-release -DartifactId=TDCOMM -Dpackaging=jar -Dfile=TDCOMM-1.0-release.jar mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.2.0 -Dpackaging=jar -Dfile=ojdbc14-10.2.0.2.0.jar

mvn install:install-file -DgroupId=com.tangdi.production -Dversion=2.0.1-release -DartifactId=TDBASE -Dpackaging=jar -Dfile=TDBASE-2.0-release.jar

bin\activemq.bat start xbean:examples/conf/activemq-demo.xml

maven 生成项目 mvn archetype:generate -DgroupId=org.sonatype.mavenbook.ch03
-DartifactId=simple
-DpackageName=org.sonatype.mavenbook 生成web项目 mvn archetype:generate -DgroupId=org.sonatype.mavenbook.ch05
-DartifactId=simple-webapp -DpackageName=org.sonatype.-DarchetypeArtifactId=maven-archetype-webapp 运行java 类: mvn exec:java -Dexec.mainClass=com.webimation.activemq.topic.Publisher -Dexec.args="H:\worktemp\riskytrans\src\main\resources\transFiles" 检查并下载依赖: mvn clean install 编译: mvn compile 打包 和install有何区别? mvn package 检查并列出依赖: mvn dependency:resolve 拷贝依赖 mvn dependency:copy-dependencies 列出依赖树: mvn dependency:tree 测试: mvn test mvn test -Dmaven.test.failure.ignore=true 生成jar包: mvn install assembly:assembly 生成普通APP: mvn archetype:create -DgroupId=com.sonatype.maven.ch04
-DartifactId=simple-weather
-DpackageName=com.sonatype.maven
-Dversion=1.0 生成web-app mvn archetype:create -DgroupId=com.sonatype.maven.ch05
-DartifactId=simple-webapp
-DpackageName=com.sonatype.maven
-DarchetypeArtifactId=maven-archetype-webapp 资源文件输出 mvn resources:resources mvn compiler:testCompile mvn surfire:test 添加jetty支持: 在build段中添加: org.mortbay.jetty maven-jetty-plugin

注意:上述引用已经无效,需要用下面的: ​ org.mortbay.jetty
​ jetty-maven-plugin
​ 7.6.10.v20130312 ​
运行jetty: mvn jetty:run 运行后访问的页面为:http://localhost:8080,后面不需要再带项目名,第一种要带项目名 生成数据库: mvn hibernate3:hbm2ddl 生成文档: mvn site help:active-profiles 列出当前构建中活动的Profile(项目的,用户的,全局的)。 help:effective-pom 显示当前构建的实际POM,包含活动的Profile。 help:effective-settings 打印出项目的实际settings, 包括从全局的settings和用户级别settings继承的 配置。 help:describe 描述插件的属性。它不需要在项目目录下运行。但是你必须提供你想要描述插件 的 groupId 和 artifactId。

mvn hibernate3:hbm2ddl

mvn dependency:build-classpath 显示所有依赖的路径 mvn help:describe -Dcmd=site

• ${basedir} 项目根目录 • ${project.build.directory} 构建目录,缺省为target • ${project.build.outputDirectory} 构建过程输出目录,缺省为target/classes • ${project.build.finalName} 产出物名称,缺省为${project.artifactId}-${project.version} • ${project.packaging} 打包类型,缺省为jar • ${project.xxx} 当前pom文件的任意节点的内容 • ${project.build.sourceDirectory} :项目的主源码目录,默认为 src/main/java • ${project.build.testSourceDirectory} :项目的测试源码目录,默认为 src/test/java • ${project.testOutputDirector} :项目测试代码编译输出目录,默认为 target/test-classes/ • ${project.groupId} :项目的 groupId • ${project.artifactId} :项目的 artifactId • ${project.version} :项目的 version ,与 ${version} 等价

方式1:dependency 本地jar包 ​ ​ com.hope.cloud ​ cloud ​ 1.0 ​ system ​ ${basedir}/lib/cloud.jar ​ 方式2:编译阶段指定外部lib ​ ​ maven-compiler-plugin ​ 2.3.2 ​ ​ 1.8 ​ 1.8 ​ UTF-8 ​ ​ lib ​ ​ ​ 方式3:将外部jar打入本地maven仓库 ​ cmd 进入jar包所在路径,执行以下命令 ​ mvn install:install-file -Dfile=cloud.jar -DgroupId=com.hope.cloud -DartifactId=cloud -Dversion=1.0 -Dpackaging=jar ​ 引入依赖 ​ ​ com.hope.cloud ​ cloud ​ 1.0 ​

maven wrapper: 1.在项目目录下安装wrapper mvn -N io.takari:maven:wrapper 安装后在目录下可看到 mvnw(linux),及mvnw.cmd(win)的批处理文件 2.使用 mvnw clean install 3.修改maven版本 mvn -N io.takari:maven:wrapper -Dmaven=3.1.0

==========Maven下载源码和javadocs============ 1:Maven命令下载源码和javadocs 当在IDE中使用Maven时如果想要看引用的jar包中类的源码和javadoc需要通过maven命令下载这些源码,然后再进行引入,通过mvn命令能够容易的达到这个目的: mvn dependency:sources mvn dependency:resolve -Dclassifier=javadoc 2:通过配置文件添加 打开maven配置文件 setting.xml文件(.../.m2/settings.xml) 增加如下配置: ​ downloadSources ​ ​ true ​ true

downloadSources 3.配置eclipse Window > Preferences > Maven and checking the "Download Artifact Sources" and "Download Artifact JavaDoc" options

内建的基本变量

${basedir} : 包含pom.xml文件的路径

${version} : 与 {project.version} 或者 {pom.version} 一致

Pom或者项目变量

Pom或者项目变量均可通过pom. 或者 poject. 前缀来访问

${project.build.directory} : 编译打目录。就是${basedir}/target/

${pom.project.build.directory} 与 ${project.build.directory}一样

${project.build.outputDirectory} : 编译输出目录。就是 ${basedir}/target/classes/

${project.name} 或者 ${pom.name} : 项目名称

${project.version} 或者 ${pom.version} : 项目版本

${project.build.finalName} : 项目打包后的package的名字

Setting文件中的变量值

settings文件中定义的变量可以通过通过settings.前缀来访问

${settings.localRepository} : 本地.m2文件夹的路径

系统变量

${env.M2_HOME} : 系统maven的安装目录

${java.home} : 系统java安装目录

1
https://gitee.com/zhrun8899/learning-notes.git
git@gitee.com:zhrun8899/learning-notes.git
zhrun8899
learning-notes
learning-notes
master

搜索帮助