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

Maven远程部署项目到Tomcat7

2015-10-09 14:34 465 查看
tomcat-users.xml文件中如下配置:

1.  <role rolename="manager-gui"/>  
2. 
<role rolename="manager-script"/>  
3.  <user username="suny" password="123456" roles="manager-gui, manager-script" />  

Maven工程中pom.xml文件如下配置:

1.    <plugin>  
2.       <groupId>org.codehaus.mojo</groupId>  
3.       <artifactId>tomcat-maven-plugin</artifactId>  
4.       <configuration>  
5.          <url>http://192.168.1.200:8080/manager/text</url>  
6. 
        <server>test</server>  
7.         <path>/MyService</path>  
8.       </configuration>  
9.    </plugin>  

在~/.m2/settings.xml文件中如下配置:

1.  <?xml version="1.0" encoding="UTF-8"?>  
2. 
<settings>  
3.    <servers>  
4. 
    <server>  
5.        <id>test</id>  #对应pom.xml 中的 <server>test</server>  
6. 
      <username>suny</username>   #对应tomcat-users.xml中的用户名,密码
7.        <password>123456</password>  
8. 
    </server>  
9.    </servers>  
10.
</settings>  

eclipse中配置部署



1.  mvn tomcat:deploy    
2. mvn tomcat:undeploy    
3. mvn tomcat:start    
4. mvn tomcat:stop  
5. mvn tomcat:redeploy

 
部署时出现的问题:
1、web.xml which will be ignored 
[WARNING] Warning: selected war files include aWEB-INF/web.xml which will be ignored (webxml attribute is missing from wartask, or ignoreWebxml attribute is specified as 'true')   
在使用Maven 编译项目的时候会出现 
[WARNING] Warning: selected war files include aWEB-INF/web.xml which will be ignored  
解决方法:  
pom.xml增加

<plugin>

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

        <artifactId>maven-war-plugin</artifactId>

        <version>2.1.1</version>

        <configuration>

               <packagingExcludes>WEB-INF/web.xml</packagingExcludes>

        </configuration>

 </plugin>

 
2、内存溢出
[ERROR] Java heap space -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Mavenwith the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debuglogging.
[ERROR]
[ERROR] For more information about the errors and possiblesolutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/OutOfMemoryError 解决方法:
调整java的堆大小的值。
a、在maven中设置
1、Windows环境中
2、找到文件%M2_HOME%\bin\mvn.bat,这就是启动Maven的脚本文件,在该文件中你能看到有一行注释为:
  @REM set MAVEN_OPTS=-Xdebug -Xnoagent-Djava.compiler=NONE...
它的意思是你可以设置一些Maven参数,我们就在注释下面加入一行:
 
setMAVEN_OPTS= -Xms128m -Xmx512m
之后,当你运行Maven命令如 mvn -version 的时候,你会看到如下的输出:
E:\test>mvn -version
E:\test>setMAVEN_OPTS= -Xms128m -Xmx512m

Maven version: 2.0.9

Java version: 1.6.0_07

OS name: "windows 2003" version: "5.2" arch:"x86" Family: "windows"
我们看到,配置的Maven选项生效了,
b、m2eclipse中
类似以上的方法都会失效,所幸m2eclipse提供了配置点。步骤如下:
项目上右击 -> Run As -> Run Configurations -> Maven Build
上右击 -> New
这时会看到一个maven运行配置对话框,这里面其它的配置我不多解释了,为了解决内存溢出的问题,我们可以选择第二个TAB: JRE,然后在VM arguments中输入配置如:-Xms128m -Xmx512m。
3、403错误
maven 403 No server username specified - using default  Cannot invoke Tomcat manager: Server rened HTTP response code: 403 for URL
 [ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy(default-cli) on project my_struts: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/deploy?path=%2Fframework&war=
INFO] Deploying war to http://localhost:8080/report
[DEBUG] No server username specified - using default
解决方法:
这个问题是因为你的tomcat里面没有写权限。
见步骤3中tomcat-user.xml的配置
4、 Application already exists
这是因为已经存在同名的war包。

[ERROR]
Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy
(default-cli) on projectcomponentlibrary:
Cannot invoke Tomcat manager: FAIL
- Application already exists at path
/comlib ->
[Help 1]

org.apache.maven.lifecycle.LifecycleExecutionException:
Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy
(default-cli) on project componentlibrary:
Cannot invoke Tomcat manager: FAIL
- Application already exists at path
/comlib

               at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)

        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)

        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)

        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)

        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)

        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)

解决方法:
a、更换<path>/comlib</path> 中的路径
b、增加<update>true</update> 

<plugin> 
                                                            
<groupId>org.apache.maven.plugins</groupId> 
                                                            
<artifactId>maven-war-plugin</artifactId> 
                                                            
<version>2.1.1</version> 
                                                            
<configuration> 
                                                                           
<packagingExcludes>WEB-INF/web.xml</packagingExcludes> 
                                                            
</configuration> 
</plugin> 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息