Eclipse中新建Maven project的web项目
配置Maven项目
点击项目右键>>Build Path>>Configure Build Path
1,将项目修改成web项目
2,删除web项目发布时无用代码
3,配置Tomcat
tomcat根目录下,conf -> tomcat-users.xml
<role rolename="role1"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="admin" roles="manager-gui"/>
4,配置pom.xml文件
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<!-- 只在编译、测试时候运行 -->
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>mavenweb</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<!-- 在打包成功后使用run来运行tomcat -->
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<path>项目名</path>
<server>tomcat7</server>
<!-- tomcat的管理员账号 -->
<username>admin</username>
<password>admin</password>
<!-- 这里是本地tomcat,如果是远程服务器可以改成对应的地址,实现自动部署 -->
<url>http://localhost:8080/manager</url>
<charset>UTF-8</charset>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
5,运行
右键项目,run as –> maven build… ->tomvat7:deploy
6,验证是否发布成功
找到war文件:
在项目路径中找到target –> 项目名.war;放入tomcat的webapps目录下,启动tomcat,发布成功