标签:maven servlet tomcat web app 自动部署
前面几篇文章石油maven时都是手动部署到tomcat,显然这样是很麻烦的。那么这一篇文章就来介绍一个如何使用maven快速自动的部署项目到tomcat容器中。
1、首先我们需要配置tomcat的权限,如下图,在eclipse的servers下找到tomcat-users.xml。
然后对其进行编辑,结果如下:
<tomcat-users> <role rolename="tomcat" /> <role rolename="manager" /> <role rolename="admin" /> <role rolename="manager-gui" /> <role rolename="manager-script" /> <user username="admin" password="admin" roles="tomcat,manager,admin,manager-gui,manager-script" /> </tomcat-users>此处注意一下,为了防止get请求中文乱码,建议修改一下server.xml:
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>那个URIEncoding默认是ISO-8859-1。
2、修改apache-maven-3.3.3\conf下面的setting.xml。
<servers> <span style="white-space:pre"> </span><server> <span style="white-space:pre"> </span><id>tomcat</id> <span style="white-space:pre"> </span><username>admin</username> <span style="white-space:pre"> </span><password>admin</password> <span style="white-space:pre"> </span></server> </servers>
<span style="white-space:pre"> </span><properties> <project.tomcat.version>8.0.0-RC5</project.tomcat.version> </properties> <span style="white-space:pre"> </span><dependencies> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-servlet-api</artifactId> <version>${project.tomcat.version}</version> <scope>provided</scope> </dependency> </dependencies> <span style="white-space:pre"> </span><repositories> <repository> <id>people.apache.snapshots</id> <url>http://mvnrepository.com/</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://mvnrepository.com/</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> <build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <url>http://localhost:8080/manager/text</url> <server>tomcat</server> <username>admin</username> <password>admin</password> <path>/${project.artifactId}</path> </configuration> </plugin> </plugins> </build>4、创建一个goals,如下配置,注意被框中的地方,如果想更省事,可以配置common,把run选中,这里就不多说了。然后运行刚才配置的tomcat7:redeploy就OK了。
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:maven servlet tomcat web app 自动部署
原文地址:http://blog.csdn.net/w2865673691/article/details/47664779