一、Maven安装配置
1.1、Windows
1.1.1、配置环境变量
MAVEN_HOME
F:\dev\Java\apache-maven-3.1.1
PATH
%JAVA_HOME%\bin;%MAVEN_HOME%\bin
1.1.2、设置Maven仓库
修改配置文件%MAVEN_HOME%\conf\settings.xml
J:\\child_1\\Maven_localRepository\\localRepository_zqx
1.2、Linux
export MAVEN_HOME=/omnt/yjx/maven/maven
export PATH=$PATH:$MAVEN_HOME/bin:$ANT_HOME/bin
export MAVEN_OPTS="-Xmx2g -XX:MaxPermSize=1g -XX:ReservedCodeCacheSize=1g"
二、pom.xml详解
各标签含义
三、Maven命令
mvn compile编译
mvn clean delete target
mvn clean compile
mvn clean test
mvn clean package 只是生成jar包,not copy to localRepository
mvn clean install 不仅生成jar包,而且把生成的jar包copy to localRepository
mvn clean deploy 拷贝到私有服务器nexus命令
mvn clean deploy 将web项目部署到Tomcat命令
mvn package 生成直接运行的jar包(Hello-0.0.1-SNAPSHOT.jar)
mvn jar:jar 错误: 找不到或无法加载主类 cn.itcast.maven.Maven_demo1.Hello
mvn source:jar 生成源代码jar包(Hello-0.0.1-SNAPSHOT-sources.jar)
mvn javadoc:jar 生成doc jar包(Hello-0.0.1-SNAPSHOT-javadoc.jar)
mvn javadoc:javadoc 生成doc文件夹(apidocs文件夹)
mvn clean package -Denv=pre -Dmaven.test.skip=true
四、pom.xml build插件
maven-jar-plugin
maven-source-plugin
<!--配置打jar包的插件(Maven_demo-0.0.1-SNAPSHOT.jar) -->
<build>
<plugins>
<!-- 打jar包的插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>cn.itcast.maven.Maven_demo.Hello</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- 打源码包的插件(Maven_demo-0.0.1-SNAPSHOT-sources.jar) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<goals>
<goal>jar-no-fork</goal>
</goals>
<phase>
verify
</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
maven-assembly-plugin
<!--
bind the maven-assembly-plugin to the package phase
this will create a jar file without the storm dependencies
suitable for deployment to a cluster.
-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>cn.yjx.rtc.MonitorTopology</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
<!-- <goal>assembly</goal> -->
</goals>
</execution>
</executions>
</plugin>
maven-compiler-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
maven-shade-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>cn.yjx.bigdata.RTC</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
五、其他
profile介绍
http://haohaoxuexi.iteye.com/blog/1900568