使用Maven自動部署Tomcat 6和Tomcat 7下Web應用

使用Maven自動部署Tomcat 6和Tomcat 7下Web應用html

  1. 開啓Tomcat遠程管理權限

在tomcat的config目錄下的tomcat-users.xml文件,web

<role rolename="manager-gui"/>apache

<role rolename="manager-script"/>tomcat

<role rolename="manager-jmx"/>session

<role rolename="manager-status"/> app

<role rolename="admin-gui"/> eclipse

<role rolename="admin-script"/> maven

<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>post

 

很少說,此處多給些權限,別小氣,不然容易沒有權限進行部署(tomcat給的原始配置示例都被<!---->註釋掉了)。配置是否成功的驗證方法是重啓Tomcatà登錄tomcat管理控制檯à輸入用戶名密碼後(admin/admin)à部署一個war應用試試,成功則OK,不成功就不要往下走了。ui

 

  1. 配置tomcat6-maven-plugintomcat7-maven-plugin

工程POM中,配置插件:

Tomcat 6的配置示例以下:

<plugin>

<groupId>org.apache.tomcat.maven</groupId>

<artifactId>tomcat6-maven-plugin</artifactId>

<version>2.2</version>

<configuration>

<url>http://16.158.165.0:8080/manager</url><!-- http://127.0.0.1:8080/manager-->

<username>admin</username>

<password>admin</password>

<path>/BizService</path><!--WEB應用上下文路徑-->

</configuration>

</plugin>

 

Tomcat 7的配置示例以下:(注意紅色高亮部分差別)

<plugin>

<groupId>org.apache.tomcat.maven</groupId>

<artifactId>tomcat7-maven-plugin</artifactId>

<version>2.2</version>

<configuration>

<url>http://16.158.165.0:8080/manager/text</url>

<username>admin</username>

<password>admin</password>

<path>/BizService</path><!--WEB應用上下文路徑-->

</configuration>

</plugin>

 

  1. 部署相關命令

Tomcat 6部署及從新部署命令

mvn tomcat6:deploy

mvn tomcat6:redeploy

 

Tomcat 7部署及從新部署命令

mvn tomcat7:deploy

mvn tomcat7:redeploy

 

  1. 備註

m2eclipse也是如此配置。

<username><password>也能夠用<server>方式配置,就是在setting文件中配置用戶名密碼,POM中只是指定server id,此處不詳述。

 

  1. 詳細信息(來自官網2.3版本)

Goal

Description

tomcat6:deploy

Deploy a WAR to Tomcat.

tomcat6:deploy-only

Deploy a WAR to Tomcat without forking the package lifecycle.

tomcat6:exploded

Deploy an exploded WAR to Tomcat.

tomcat6:help

Display help information on tomcat6-maven-plugin.
Call mvn tomcat6:help -Ddetail=true -Dgoal=<goal-name> to display parameter details.

tomcat6:info

Lists information about the Tomcat version, OS, and JVM properties.

tomcat6:inplace

Deploy a WAR in-place to Tomcat.

tomcat6:list

Lists all the currently deployed web applications in Tomcat.

tomcat6:redeploy

Redeploy a WAR in Tomcat. (Alias for the deploy goal with its update parameter set to true.)

tomcat6:redeploy-only

Redeploy a WAR in Tomcat without forking the package lifecycle. (Alias for the deploy-only goal with its update parameter set to true.)

tomcat6:reload

Reload a WAR in Tomcat.

tomcat6:resources

Lists JNDI resources in Tomcat.

tomcat6:roles

Lists security roles in Tomcat.

tomcat6:run

Runs the current project as a dynamic web application using an embedded Tomcat server.

tomcat6:run-war

Runs the current project as a packaged web application using an embedded Tomcat server.

tomcat6:run-war-only

Same as run-war goal without forking the package cycle.

tomcat6:sessions

Lists session information for a WAR in Tomcat.

tomcat6:shutdown

Shuts down all possibly started embedded Tomcat servers. This will be automatically done through a shutdown hook or you may call this Mojo to shut them down explictly.

By default the shutdown goal is not bound to any phase. For integration tests you might want to bind it topost-integration-test.

tomcat6:start

Start a WAR in Tomcat.

tomcat6:stop

Stop a WAR in Tomcat.

tomcat6:undeploy

Undeploy a WAR from Tomcat.

相關文章
相關標籤/搜索