1.常用命令参数
进行编译
mvn compile
进行打包
#测试并打包 mvn package #直接打包,不进行测试 mvn package -DskipTests=true #打Jar包 mvn jar:jar #打War包 mvn war:war #打War包但不执行最后的压缩 mvn war:exploded
进行测试
#编译单元测试 mvn test-compile #编译并允许单元测试 mvn test
安装到本地repository
mvn install mvn install -DskipTests=true mvn install -DskipTests=true --fail-at-end #安装jar包到本地仓库 mvn install:install-file -DgroupId=groupId -DartifactId=artifactId -Dversion=1.0.0 -Dpackaging=jar -Dfile=xxx.jar
安装到远程repository
mvn deploy
进行清理
mvn clean
生成网站
#生成网站 mvn site #生成网站并发布 mvn site-deploy
打包源码包
#打包源码 mvn source:jar #下载项目源码 mvn dependency:sources -DdownloadSources=true -DdownloadJavadocs=true
打包测试源码包
mvn source:test-jar
拷贝依赖到target目录
#拷贝依赖 mvn dependency:copy-dependencies #依赖分析 mvn dependency:analyze mvn dependency:tree
生成ecplise项目
mvn eclipse:eclipse
生成ecplise项目
mvn idea:idea
生成文档
#单模块项目生成文档 mvn javadoc:javadoc #多模块项目生成文档 mvn javadoc:aggregate
创建Jar项目
mvn archetype:create -DgroupId=gourpid -DartifactId=artifactId
创建War项目
mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=gourpid -DartifactId=artifactId
2.settings.xml
<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"] <localRepository>X:/Maven/repository</localRepository> <servers> <server> <id>neo-public</id> <username>username</username> <password>password</password> </server> <server> <id>neo-releases</id> <username>username</username> <password>password</password> </server> <server> <id>neo-snapshots</id> <username>username</username> <password>password</password> </server> </servers> <mirrors> <mirror> <id>neo-public</id> <name>Neohope Nexux Public Mirror</name> <url>http://192.168.xxx.xxx:8081/nexus/content/groups/public</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <profiles> <profile> <id>myprofile</id> <repositories> <repository> <id>neo-public</id> <name>Neohope Nexux Public Mirror</name> <url>http://192.168.xxx.xxx:8081/nexus/content/groups/public</url> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>myprofile</activeProfile> </activeProfiles> </settings>
3.pom.xml
<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.neohope.xxx</groupId> <artifactId>xxx-xxx</artifactId> <version>1.0.0</version> <packaging>jar</packaging> <name>xxx-xxx</name> <url>http://neohope.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <nexus.url>http://192.168.xxx.xxx:8081</nexus.url> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <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> <distributionManagement> <repository> <id>neo-releases</id> <name>Internal Releases</name> <url>${nexus.url}/nexus/content/repositories/releases</url> </repository> <snapshotRepository> <id>neo-snapshots</id> <name>Internal Snapshots</name> <url>${nexus.url}/nexus/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement> </project>