How to deploy Maven based war file to Tomcat
2012-02-05 00:50
316 查看
How to deploy Maven based war file to Tomcat
Published: April 19, 2011 , Updated: April 19, 2011 , Author: mkyongHere we show you how to use Maven-Tomcat plugin to package and deploy a WAR file to Tomcat.1. Tomcat Authentication
First, add an user with administrator access right for Tomcat. To add Tomcat user, edit this file – “%TOMCAT_PATH%/conf/tomcat-users.xml“.
File : tomcat-users.xml
<?xml version='1.0' encoding='utf-8'?> <tomcat-users> <role rolename="manager"/> <role rolename="admin"/> <user username="admin" password="password" roles="admin,manager"/> </tomcat-users>Later, you will use the user “admin” to do the deployment.
2. Maven Authentication
In Maven side, you need to add the same user authentication information in “%MAVEN_PATH%/conf/settings.xml“.
File : settings.xml
//... <server> <id>TomcatServer</id> <username>admin</username> <password>password</password> </server> //...
3. Maven-Tomcat-Plugin
Declare “Maven-Tomcat plugin” and related Tomcat server detail in yourpom.xmlfile.
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <url>http://127.0.0.1:8080/manager</url> <server>TomcatServer</server> <path>/mkyongWebApp</path> </configuration> </plugin>See a full pom.xml file.
<project xmlns="http://maven.apache.org/POM/4.0.0"How it works ?
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>com.mkyong</groupId>
<artifactId>mkyongweb-core</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>mkyongweb-core Maven Webapp</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<!-- Maven Tomcat Plugin -->
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <url>http://127.0.0.1:8080/manager</url> <server>TomcatServer</server> <path>/mkyongWebApp</path> </configuration> </plugin>
<!-- Maven compiler plugin -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
During deployment, it tell Maven to deploy the WAR file to Tomcat server (http://127.0.0.1:8080/), on path “/mkyongWebApp“, and using “TomcatServer” (in
settings.xml) username and password for authentication.
4. Deploy to Tomcat
Issue “mvn tomcat:deploy” to package your project in a WAR file, and deploy it to Tomcat server. To verify it, just access to the Tomcat’s manager page and make sure “/mkyongWebApp” path is existed.
URL : http://127.0.0.1:8080/manager/
![](http://www.mkyong.com/wp-content/uploads/2011/04/deployed-maven-tomcat-plugin.png)
How to redeploy ?
For subsequent deployment, where “mkyongWebApp” web application is existed, you should use “
mvn tomcat:redeploy” instead.For more usages, please refer to this Maven-Tomcat plugin page.
相关文章推荐
- How to create a Maven web app and deploy to Tomcat - fast
- How to deploy maven project to tomcat inside your eclipse
- How to create a Maven web app and deploy to Tomcat - fast
- How to create a Maven web app and deploy to Tomcat - fast
- How to create a Maven web app and deploy to Tomcat - fast
- how-to-load-resource-from-jar-file-packaged-in-a-war-file
- Hudson + SVN + Maven 持续集成实现自动化编译、打包、部署(over SSH 和 Deploy war/ear to a container 两种部署方式)
- deploy spring war to tomcat.
- Jenkins构建项目时构建成功但不部署到tomcat的webapps下(Build step 'Deploy war/ear to a container' marked build as fai)
- Maven - Deploy war in Tomcat 7 & 8
- Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.0:deploy
- Maven-008-Nexus 私服部署发布报错 Failed to deploy artifacts: Failed to transfer file: ... Return code is: 4X
- How To Convert Maven Based Java Project To Support Eclipse IDE
- How-to: deploy hadoop client with some special user based on acl enbaled cluster
- Hot Deploy maven project from eclipse to tomcat
- How to create a jar file with Maven
- How to exclude jars generated by maven war plugin
- How to export class from xml schema file
- Tomcat常见问题解决 - The web application appears to have started a thread named [FileWatchdog]