无需配置MAVEN_HOME直接添加path环境变量即可
但要保证JAVA_HOME配置指向JDK目录
confsettings.xml中配置
<localRepository>D:RepositoryMavenRepository</localRepository>
mirrors节点中配置
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
进入文件夹目录
####################################################################
下载普通测试项目
mvn archetype:generate -DgroupId=com.guojun -DartifactId=mvn-quickstart -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
进入pom.xml所在目录
设置打包类型可省略<packaging>jar<packaging>
mvn package
运行
java -cp target/mvn-quickstart-1.0-SNAPSHOT.jar com.guojun.App
mvn生命周期常用阶段
mvn compile 编译生成target文件夹
mvn test 单元测试
mvn package 项目打包
mvn install 安装到本地仓库中
mvn post-site 生成站点之后做验证
mvn site-deploy 发布到远程站点仓库
###################################################################
下载web项目
mvn archetype:generate
-DarchetypeGroupId=org.apache.maven.archetypes
-DarchetypeArtifactId=maven-archetype-webapp
-DgroupId=com.mycompany.app
-DartifactId=my-webapp
打成war包
mvn package
验证
mvn verify
#####################################################
maven发布一个web项目到tomcat
tomcat7 jdk1.6 maven3.6
tomcat-users.xml配置
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="admin" roles="manager-gui,manager-script"/>
maven settind.xml配置
<server>
<id>tomcat7</id>
<username>admin</username>
<password>admin</password>
</server>
项目pom.xml中配置
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>tomcat7</server>
<username>admin</username>
<password>admin</password>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>people.apache.snapshots</id>
<url>
http://repository.apache.org/content/groups/snapshots-group/
</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<name>Apache Snapshots</name>
<url>
http://repository.apache.org/content/groups/snapshots-group/
</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
打包发布命令
mvn tomcat7:deploy即可.war包发布到webapps下并自动解压直接输入项目名可访问
##########################################################
发布到tomcat9时不能在浏览器打开控制台页面(/manager/html),否则无法部署