一、配置环境变量
JAVA_HOME=/d/jdk8;
MAVEN_HOME=/d/maven339;
M2_HOME=/d/maven339;
PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export MAVEN_HOME
export M2_HOME
export PATH
export CLASSPATH
mvn -v
二、设置仓库
修改%MAVEN_HOME%/settings.xml
3.1 远程仓库
<mirror>
<id>CN</id>
<name>OSChina Central</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
3.2 本地仓库
<localRepository>/d/repository</localRepository>
三、新建项目
2.1建普通目录
mvn archetype:generate -DgroupId=com.bkdwei -DartifactId=test2 -DpackageName=com.bkdwei.test2
2.2新建web项目
mvn archetype:generate -DgroupId=com.bkdwei -DartifactId=testWeb3 -DarchetypeArtifactId=maven-archetype-webapp
四、转换成eclipse项目
mvn eclipse:eclipse -Dwtpversion=2.0
五、指定编码格式
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.7</jdk.version>
<spring.version>4.1.1.RELEASE</spring.version>
<downloadJavadocs>true</downloadJavadocs>
</properties>
七、添加远程仓库(pom.xml)
<repositories>
<repository>
<id>maven repo</id>
<url>http://mvnrepository.com/artifact/</url>
</repository>
</repositories>
八、添加依赖包
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
九、指定项目build方式
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
十、打包
mvn package
十一、安装第三方库到本地仓库
mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code -DartifactId=kaptcha -Dversion={version} -Dpackaging=jar
十二、创建文档
mvn site
十三、将项目安装到Maven本地资源库
mvn install
十四、发布项目
%TOMCAT7_PATH%/conf/tomcat-users.xml 设置用户
%MAVEN_PATH%/conf/settings.xml 设置登录用户
pom.xml 设置发布路径
mvn tomcat7:deploy 或者mvn tomcat7:run
六、配置ssh
<!– 属性配置 –>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<!– 添加SSH依赖 –>
<!– Struts2 –>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.1</version>
</dependency>
<!– 添加Hibernate依赖 –>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.5.Final</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!– 添加Log4J依赖 –>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.6.4</version>
</dependency>
<!– 添加javassist –>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.11.0.GA</version>
</dependency>
<!– 添加Spring依赖 –>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
</dependencies>