maven发布项目到本地tomcat

本文介绍了如何配置Maven插件来发布项目到本地Tomcat服务器,并且详细说明了配置过程中涉及的用户名和密码设置。通过正确的配置,可以使用Maven指令成功部署应用到Tomcat的Web Application Manager页面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

添加plugin:

                       <plugin>
				<!-- 使用maven的tomcat插件打包并部署war文件到tomcat -->
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<version>2.0</version>
				<configuration>
				    <path>/${project.build.finalName}</path>  
					<url>http://localhost:8080/manager/text</url>
					<server>tomcat</server>
					<username>tomcat</username>
					<password>password</password>
				</configuration>
			</plugin>

			<plugin>
				<!-- 这里版本为1.7 请注意编译版本 否则会报错 -->
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
					<encoding>${project.build.sourceEncoding}</encoding>
				</configuration>
			</plugin>
其中用户名和密码的配置可以理解为maven为了和本地tomcat打交道而由tomcat的配置的口令,首先要在tomcat安装目录下conf文件夹下的tomcat-users.xml文件中配置:

<tomcat-users>
<!--
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary.
-->
<!--
  NOTE:  The sample user and role entries below are wrapped in a comment
  and thus are ignored when reading this file. Do not forget to remove
  <!.. ..> that surrounds them.
-->
    <!-- maven发布到tomcat -->
   <role rolename="manager-gui"/>    
   <role rolename="manager-script"/>    
   <user username="tomcat" password="password" roles="manager-gui, manager-script"/>
  
</tomcat-users>

这里配置好后,启动tomcat,在浏览器输入localhost:8080/manage会让你输入用户名密码,输入这里配置的用户名/密码,若验证通过会跳到tomcat web application Manager页面,就说明该配置是成功的,就可以往下进行;若验证不通过,会跳到一个说明页面,里面有对各role的说明(想了解上面role的童鞋请自行查看),此时再修改配置,直至验证成功。



<servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->
    <server>  
        <id>tomcat</id>  
        <username>tomcat</username>  
        <password>password</password>  
    </server> 

  </servers>
配置maven的settings.xml文件,至于settings.xml文件在你机器的哪里,请自行查找。这里的用户名和密码都与tomcat-users.xml中验证通过的用户名密码一致,这里的‘id’要与pom文件的<server>tomcat</server>一致,当然pom文件的用户名和密码也要对应。

共有三处进行了用户名密码配置。


选择eclipse的绿色启动按钮的下拉列表的run configurations...,新增一个maven指令“tomcat7:deploy”,运行指令前先启动tomcat,

不出意外就发布成功。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值