有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Maven部署到Tomcat

我想将基于Maven的war文件部署到Tomcat。 使用的技术:

Maven 3.1.1 Eclipse 4.2 jdk7 弹簧4.1.1。释放 雄猫7 Logback 1.0.13

我的maven文件中有这个插件:

<!-- For Maven Tomcat Plugin -->
          <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <url>http://localhost:8080/manager/text</url>
                <server>TomcatServer</server>
                <path>/DevicesCloudWebApp</path>
                <username>admin</username>
                <password>admin</password>
                <update>true</update>
            </configuration>
          </plugin>

但是当我使用命令mvn tomcat7:deploy部署时

我有一个错误:

    [DEBUG] Connection 0.0.0.0:62265<->127.0.0.1:8080 closed
   [INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:deploy (default-cli) > package @ DevicesCloudWebApp >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ DevicesCloudWebApp ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ DevicesCloudWebApp ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ DevicesCloudWebApp ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/nullpointer/Development/J2EE/eclipseWSJ2EE/DevicesCloudWebApp/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ DevicesCloudWebApp ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ DevicesCloudWebApp ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ DevicesCloudWebApp ---
[INFO] Packaging webapp
[INFO] Assembling webapp [DevicesCloudWebApp] in [/Users/nullpointer/Development/J2EE/eclipseWSJ2EE/DevicesCloudWebApp/target/DevicesCloudWebApp]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/nullpointer/Development/J2EE/eclipseWSJ2EE/DevicesCloudWebApp/src/main/webapp]
[INFO] Webapp assembled in [97 msecs]
[INFO] Building war: /Users/nullpointer/Development/J2EE/eclipseWSJ2EE/DevicesCloudWebApp/target/DevicesCloudWebApp.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:deploy (default-cli) < package @ DevicesCloudWebApp <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:deploy (default-cli) @ DevicesCloudWebApp ---
[INFO] Deploying war to http://localhost:8080/DeviceslCloudWebApp  
Uploading: http://localhost:8080/manager/text/deploy?path=%2FDeviceslCloudWebApp
2170/6062 KB   
[INFO] I/O exception (java.net.SocketException) caught when processing request: Broken pipe
[INFO] Retrying request
Uploading: http://localhost:8080/manager/text/deploy?path=%2FDeviceslCloudWebApp
2198/6062 KB   
[INFO] I/O exception (java.net.SocketException) caught when processing request: Broken pipe
[INFO] Retrying request
Uploading: http://localhost:8080/manager/text/deploy?path=%2FDeviceslCloudWebApp
2176/6062 KB   
[INFO] I/O exception (java.net.SocketException) caught when processing request: Broken pipe
[INFO] Retrying request
Uploading: http://localhost:8080/manager/text/deploy?path=%2FDeviceslCloudWebApp
2188/6062 KB   
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.922 s
[INFO] Finished at: 2016-12-02T20:57:29+01:00
[INFO] Final Memory: 16M/303M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project DevicesCloudWebApp: Cannot invoke Tomcat manager: Broken pipe -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

共 (1) 个答案

  1. # 1 楼答案

    尝试添加如下所示的身份验证配置

    <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>${tomcat7-maven-plugin.version}</version>
            <configuration>
                <url>http://localhost:8080/manager/text</url>
                <server>tomcat</server>
                <username>admin1</username>
                <password>admin1</password>
                <path>/${project.artifactId}</path>
                <update>true</update>
             </configuration>
    </plugin>
    

    在tomcat中更新角色配置,如下所示->$CATALINA_HOME/conf/tomcat-users.xml<tomcat-users>元素中

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