声明,此文章为本人原创!首发CSDN白菜便是真理,太阳即是正义 - 题记
此时我是怀着激动的心情写下这篇博客的...经过三个小时的不懈努力 成功将maven的webapp发布到tomcat上
这是搭架子的前提... ,首先来看一下我们的工具版本... 都是 16
Maven版本:3.39 :Bin 下载地址 :
http://apache.fayea.com/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zipTomcat版本:8.56
JDK:8u31
eclipse:Neon 1
OS:Win10
Step 1:Download Maven 其他的工具我个人认为大家都有,所以不一一介绍了。
下载完Maven之后,进行解压缩处理,我这里存放到C盘根目录。
环境变量配置:
M2_HOME :Maven根目录
path:%M2_HOME%\bin;
这个和JDK配置有些类似,很简单。
保存 Win+R CMD 输入 mvn -version 如果可以查看到Maven版本便是配置成功
Step 2:配置setting.xml
首先需要说明的是在我们第一次运行Maven的时候是没有.m2这个目录的(这个目录在home目录下,WIndows通常是C\Users\你使用的用户文件夹),我们需要使用mvn help:system 来进行创建.m2目录,创建好之后,我们需要将解压目录下的Maven\Conf\Setting.xml 复制到我们的.m2目录,我们首先设置一下远程仓库的地址,以便于下载依赖Jar包
编辑setting.xml ,找到<mirrors></mirrors> 节点,进行以下配置,此配置表示连接的远程仓库为阿里云节点
[html] view plain copy
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>
http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>
http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
此时的setting.xml 我们就进行了简单的配置
Step 3 :通过mvn 命令去创建 WebApp项目
[plain] view plain copy
mvn archetype:generate -DarchetypeCatalog=local -DgroupId=com.svgteam -DartifactId=springmvcmavendemo -DarchetypeArtifactId=maven-archetype-webapp
其中 -archetypeCatalog 表示远程仓库,-groupId 表示组id , -artifactId 表示项目id archetypeArtifactId 这个表示创建的项目类型,我选择的是maven-archtype-webapp
回车后有两个选项需要输入,我后期会补上现在先马克一下,其实大家可以根据提示自己填写完成。
Step 4 :将创建好的Maven项目导入Eclipse (默认创建的路径为home目录下)
File --》 import --》Existing Maven Project
将项目导入
Step 5 :配置 Tomcat
需要修改tomcat\conf目录下的tomcat-users.xml,加上以下几句配置
[html] view plain copy
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="antony" password="antony1111" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
Step 6 配置pom.xml
[html] view plain copy
<span style="color:#330033;"><plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<url>
http://localhost:80/manager/text</url>
<server>localhost</server>
<username>admin</username>
<password>password</password>
</configuration>
</plugin>
</plugins></span>
Step 7 : 配置项目运行环境
右键项目 Run as --》 Run Configurations --》 Maven Build --》 new Lanch Configuration
Goals 写入 tomcat:deploy
通过tomcat\bin 目录下 startup.bat 启动tomcat, run 刚刚配置的Configuration 就可以跑起来了。最后贴一下运行日志
[html] view plain copy
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demoWebApplication Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> tomcat-maven-plugin:1.1:deploy (default-cli) > package @ demoWebApplication >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demoWebApplication ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demoWebApplication ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ demoWebApplication ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\o.kEnnponN\demoWebApplication\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ demoWebApplication ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ demoWebApplication ---
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ demoWebApplication ---
[INFO] Packaging webapp
[INFO] Assembling webapp [demoWebApplication] in [C:\Users\o.kEnnponN\demoWebApplication\target\demoWebApplication]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\o.kEnnponN\demoWebApplication\src\main\webapp]
[INFO] Webapp assembled in [22 msecs]
[INFO] Building war: C:\Users\o.kEnnponN\demoWebApplication\target\demoWebApplication.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] <<< tomcat-maven-plugin:1.1:deploy (default-cli) < package @ demoWebApplication <<<
[INFO]
[INFO] --- tomcat-maven-plugin:1.1:deploy (default-cli) @ demoWebApplication ---
[INFO] Deploying war to
http://localhost:80/demoWebApplication [INFO] OK - Deployed application at context path /demoWebApplication
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.265 s
[INFO] Finished at: 2016-12-13T21:15:11+08:00
[INFO] Final Memory: 14M/491M
[INFO] ------------------------------------------------------------------------
OK,这样我们的配置就算告成了!以后会出基于Maven的SpringMVC项目搭建! 请大家继续关注!么么哒~!