对于我的学校编程考试,我们需要能够在Tomcat(7)服务器上使用maven构建和部署Spring MVC项目。大多数这些东西都在工作。 mvn clean install
提供了BUILD SUCCESS,这很好,我可以设置我的tomcat服务器。但是,当我尝试使用例如mvn tomcat7:deploy
运行或部署我的项目时,我得到一个损坏的管道异常,它看起来像这样:
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project SpringMVCBlog: Cannot invoke Tomcat manager: Broken pipe -> [Help 1]
完整堆栈跟踪(mvn tomcat7:deploy -e
)如下:
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project SpringMVCBlog: Cannot invoke Tomcat manager: Protocol wrong type for socket -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project SpringMVCBlog: Cannot invoke Tomcat manager
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
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:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Cannot invoke Tomcat manager
at org.apache.tomcat.maven.plugin.tomcat7.AbstractCatalinaMojo.execute(AbstractCatalinaMojo.java:141)
at org.apache.tomcat.maven.plugin.tomcat7.AbstractWarCatalinaMojo.execute(AbstractWarCatalinaMojo.java:68)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: java.net.SocketException: Protocol wrong type for socket
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at org.apache.http.impl.io.AbstractSessionOutputBuffer.write(AbstractSessionOutputBuffer.java:181)
at org.apache.http.impl.io.ContentLengthOutputStream.write(ContentLengthOutputStream.java:115)
at org.apache.tomcat.maven.common.deployer.TomcatManager$RequestEntityImplementation.writeTo(TomcatManager.java:880)
at org.apache.http.entity.HttpEntityWrapper.writeTo(HttpEntityWrapper.java:89)
at org.apache.http.impl.client.EntityEnclosingRequestWrapper$EntityWrapper.writeTo(EntityEnclosingRequestWrapper.java:108)
at org.apache.http.impl.entity.EntitySerializer.serialize(EntitySerializer.java:117)
at org.apache.http.impl.AbstractHttpClientConnection.sendRequestEntity(AbstractHttpClientConnection.java:265)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.sendRequestEntity(ManagedClientConnectionImpl.java:203)
at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:236)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:682)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:486)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.tomcat.maven.common.deployer.TomcatManager.invoke(TomcatManager.java:742)
at org.apache.tomcat.maven.common.deployer.TomcatManager.deployImpl(TomcatManager.java:705)
at org.apache.tomcat.maven.common.deployer.TomcatManager.deploy(TomcatManager.java:388)
at org.apache.tomcat.maven.plugin.tomcat7.deploy.AbstractDeployWarMojo.deployWar(AbstractDeployWarMojo.java:85)
at org.apache.tomcat.maven.plugin.tomcat7.deploy.AbstractDeployMojo.invokeManager(AbstractDeployMojo.java:82)
at org.apache.tomcat.maven.plugin.tomcat7.AbstractCatalinaMojo.execute(AbstractCatalinaMojo.java:132)
... 22 more
我一直在努力解决这个问题,我似乎无法找到解决方案。当我使用glassfish服务器在我的IDE(IntelliJ)中运行此项目时,它可以工作,但目标是使用终端(我在Mac上)运行它并将其部署在Tomcat服务器上。
我已经搜索了但是关于断管异常的信息不多。我发现它与Hibernate和MySQL有关。我在应用程序中有一个基本的Hibernate结构,只是一个带有一些设置的基本hibernate.cfg / xml和一个用于获取会话的Util类,因此我可以在数据库上保存和更新。 Broken Pipe会与我在项目中没有使用的连接池有关(据我所知)。
我真的希望有人能帮助我,这个问题非常令人沮丧。如果需要任何额外的代码,请告诉我!
修改
我的pom.xml的构建部分的内容:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<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>
<username>root</username>
<password>root</password>
<path>/SpringMVCBlog</path>
<update>true</update>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>SpringMVCBlog</finalName>
</build>
答案 0 :(得分:1)
我有完全相同的问题。 我直到现在才知道的唯一解决方法是切换回旧的和不受支持的org.codehaus.tomcat maven插件:
http://mvnrepository.com/artifact/org.codehaus.mojo/tomcat-maven-plugin
显然这不是最终的解决方案,虽然我现在只能像这样部署我的战争。
事实证明,如果Web上下文已经存在,则会发生此错误。不幸的是,错误消息并没有告诉我们。
我使用官方apache tomcat maven插件(link)和maven redeploy选项修复了它,因为tomcat maven插件&gt; = 2.1。
此致
马库斯
答案 1 :(得分:1)
只需使用
mvn tomcat7:重新部署
如果您的应用程序已经部署。
否则,在执行 mvn tomcat7:deploy
之前,首先需要取消部署应用程序。