maven实用命令
来源:互联网 发布:java工程师的报考条件 编辑:程序博客网 时间:2024/05/17 06:45
1 查看项目jar依赖层次关系:
在项目所在目录:shift + 右键 -》进入命令窗口,执行mvn dependency:tree
2 maven hello world构建:
1)创建my-app项目:mvn archetype:generate -DgroupId=com.mycompany.app
-DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
2)创建出的项目目录结构如下:
my-app|-- pom.xml`-- src |-- main | `-- java | `-- com | `-- mycompany | `-- app | `-- App.java `-- test `-- java `-- com `-- mycompany `-- app `-- AppTest.java
备注:The src/main/java directory contains the project source code, the src/test/java directory contains the test source,
and the pom.xml file is the project's Project Object Model, or POM.(src/main/java目录包含项目的源代码,src/test/java目
录包含测试部分的源代码,pom.xml文件是项目的项目对象模型及pom,POM=Project Object Model)
3)构建项目:
mvn package:Rather than a goal, this is a phase. A phase is a step in the build lifecycle, which is an ordered
sequence of phases.When a phase is given, Maven will execute every phase in the sequence up to and including the one
defined.
For example, if we execute the compilephase, the phases that actually get executed are:1))validate
2))generate-sources
3))process-sources
4))generate-resources
5))process-resources
6))compile
4)测试:
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App 输出结果:Hello World
3 running maven tools
1)Phases are actually mapped to underlying goals(潜在的目标由n个阶段构成)
4 maven常用命令
1)编译应用源代码:
mvn compile
2)编译test源代码并且运行单元测试用例:
mvn test
3)只编译test源代码不运行单元测试用例:
mvn test-compile
4)创建一个jar
mvn package
5)把生成的jar安装到本地资源库:
mvn install
6)surefire插件执行包含如下名字:
1))**/*Test.java
2))**/Test*.java
3))**/*TestCase.java
7)surefire插件执行默认排除的文件
1))**/Abstract*Test.java
2))**/Abstract*TestCase.java
8)清除target目录
mvn clean
9)生成一个IntelliJ IDEA描述器
mvn idea:idea(更新settings而不是开始刷新)
10)eclipse 下转换成mvn项目
mvn eclipse:eclipse
11)把资源文件加到jar中
增加${basedir}/src/main/resources,把资源文件放到该目录。任何放在${basedir}/src/main/resources目录下的目录或者文件都会打包到你的jar包中,
12)排除包含的资源文件,指定文件,filter属性指定为true
<build><resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build>
13 把自己的jar部署到远程资源库
1)在pom.xml文件中配置仓库url
<distributionManagement><repository> <id>mycompany-repository</id> <name>MyCompany Repository</name> <url>scp://repository.mycompany.com/repository/maven2</url> </repository> </distributionManagement>
2)在setting文件指定连接到仓库的认证信息
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> ... <servers> <server> <id>mycompany-repository</id> <username>jvanzyl</username> <!-- Default value is ~/.ssh/id_dsa --> <privateKey>/path/to/identity</privateKey> (default is ~/.ssh/id_dsa) <passphrase>my_key_passphrase</passphrase> </server> </servers> ... </settings>
14)构建一个web项目:
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=com.mycompany.app -DartifactId=my-webapp
必须一行作为一个命令输入进去
15)一次构建多个项目
外部总项目包含子项目,子项目和外部项目总项目pom文件放在同一个目录,子目录pom文件包含parent标签指定父项目
16)打jar包含源码包,需要使用maven提供的源码插件
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins></build>
0 0
- Maven实用命令
- maven实用命令
- maven实用
- 程序员必修改课之maven实用命令
- 实用命令
- 实用命令
- 实用命令
- 实用命令
- linux命令实用命令
- 简单maven实用配置
- Maven实用总结
- Maven实用详解
- Chrome 控制台实用实用命令
- maven命令
- maven 命令
- maven命令
- maven 命令
- MAVEN命令
- android ICS 系统启动之Logo有关学习总结
- Cocos2d-x 3.0 开发(八)骨骼动画的动态换肤
- platform_driver_probe与platform_driver_register的区别
- cocos2dx面试题(2)
- Unrecognized Windows Sockets error: 0: JVM_Bind 异常解决办法
- maven实用命令
- 黑马程序员 C语言 - 01 第一个C语言程序、基本知识
- hdu2955 - Robberies
- Cocos2d-x 3.0 开发(七)在程序中处理cocoStudio导出动画
- js获取yyyy-mm-dd格式日期
- 显示、隐藏文件和删除一个文件夹下的.svn文件
- Silverlight 运行原理 解析综合版(二)
- Cocos2d-x 3.0开发(六)使用cocoStudio创建一个骨骼动画
- 【LeetCode with Python】 Rotate List