您的位置:首页 > 运维架构 > Tomcat

maven tomcat1.7环境下构建javaweb 项目

2016-04-13 14:07 204 查看
tomcat用户权限设置


在tomcat安装路径\conf目录下tomcat-users.xml添加:

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


maven的server设置

在maven安装路径\conf目录下的setting.xml <servers>节点中添加:

pom.xml设置

在项目pom.xml中添加:

<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- 注意此处的url -->
<url>http://localhost:8080/manager/text</url>
<server>tomcat</server> <!-- 此处的名字必须和setting.xml中配置的ID一致-->
<path>/projectname</path> <!-- 此处的名字是项目发布的工程名-->
<username>admin</username>
<password>password</password>
</configuration>
</plugin>


如果项目默认的web目录为WebContent,则添加:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webResources>
<resource>
<directory>WebContent</directory>
</resource>
</webResources>
</configuration>
</plugin>


否则会报Error assembling WAR: webxml attribute is required (web.xml找不到)

运行构建命令

启动tomcat1.7(必须提前启动)

两种方式:

1、命令行:定位到项目根路径,第一次构建时运行 mvn tomcat:deploy,之后重新构建的时候运行 mvn tomcat:redeploy

2、IDE(eclipse):选择项目右击,选择Run As->Maven bulid... 在弹出的窗口中找到 Goals,第一次构建时 填入tomcat:deploy 然后点击apply run,之后填入tomcat:redeploy 然后点击apply run
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: