Java 无法执行目标 org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16230666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 05:53:57  来源:igfitidea点击:

Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli)

javaspringmaventomcat7

提问by

i am trying to do mvn tomcat:deployand i came across with the error

我正在尝试执行mvn tomcat:deploy并且遇到了错误

 [ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project appanalytix: Cannot invoke Tomcat manager: Connection refused: connect -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project appanalytix: Cannot invoke
Tomcat manager
    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)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Cannot invoke Tomcat manager
    at org.codehaus.mojo.tomcat.AbstractCatalinaMojo.execute(AbstractCatalinaMojo.java:149)
    at org.codehaus.mojo.tomcat.AbstractWarCatalinaMojo.execute(AbstractWarCatalinaMojo.java:70)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
    at sun.net.www.http.HttpClient.New(HttpClient.java:290)
    at sun.net.www.http.HttpClient.New(HttpClient.java:306)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:931)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
    at org.codehaus.mojo.tomcat.TomcatManager.invoke(TomcatManager.java:597)
    at org.codehaus.mojo.tomcat.TomcatManager.deployImpl(TomcatManager.java:662)
    at org.codehaus.mojo.tomcat.TomcatManager.deploy(TomcatManager.java:295)
    at org.codehaus.mojo.tomcat.AbstractDeployWarMojo.deployWar(AbstractDeployWarMojo.java:85)
    at org.codehaus.mojo.tomcat.AbstractDeployMojo.invokeManager(AbstractDeployMojo.java:85)
    at org.codehaus.mojo.tomcat.AbstractCatalinaMojo.execute(AbstractCatalinaMojo.java:141)

in maven\conf\settings.xml

maven\conf\settings.xml

<server>
<id>TomcatServer</id>
<username>admin</username>
<password>admin</password>
</server>

in tomcat-7.0.39\conf\tomcat-users

tomcat-7.0.39\conf\tomcat-users

 <tomcat-users>
 <role rolename="manager"/>
 <role rolename="manager-gui"/>
 <role rolename="admin"/>
 <user username="admin" password="admin" roles="admin,manager,manager-gui"/>
 </tomcat-users>

pom.xml

pom.xml

  <plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
    <mode>war</mode>
    <url>http://localhost:8080/manager</url>
    <server>TomcatServer</server>
    <path>/appanalytix</path>
  </configuration>
</plugin>

i have tried using /textand /htmlfrombut that doesn't worked ,please help me to solve this

我试过使用/text/html 但没有用,请帮我解决这个问题

采纳答案by khmarbaise

First you must be aware of the move of the tomcat-maven-pluginto the apache software foundationSecond you shouldn't put configuration stuff into maven/conf/settings.xml you should use the users settings.xml file HOME/.m2/settings.xml instead.

首先你必须知道tomcat-maven-plugin 移动apache 软件基础第二你不应该把配置的东西放到 maven/conf/settings.xml 你应该使用用户 settings.xml 文件 HOME/.m2/ settings.xml 代替。

Apart from the above you should use the following URL for accessing Tomcat:

除了上述之外,您还应该使用以下 URL 来访问 Tomcat:

http://localhost:8080/manager/html

回答by sancho21

The following way works for me.

以下方式对我有用。

  1. Please change your pom.xmlto include

    <project>
        ...
        <build>    
            <plugins>    
            ....
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <url>http://localhost:8080/manager/text</url>
                        <server>my-tomcat</server>
                        <path>/myapp</path>
                    </configuration>
                </plugin>
            </plugins>
            ...
        </build>
        ...
    </project>
    
  2. Make sure your Tomcat 7 server have the following lines on TOMCAT_HOME/conf/tomcat-users.xml:

    <!-- Role to manage WAR files via HTML /manager. The name should be as is! -->
    <role rolename="manager-gui"/>
    <!-- Role to manage WAR files via script like Maven. The name should be as is! -->
    <role rolename="manager-script"/>
    
    <!-- One user cannot have manager-gui and manager-script roles -->
    <user username="managerGui" password="managerPwd" roles="manager-gui"/>
    <user username="manager" password="managerPwd" roles="manager-script"/>
    
  3. Configure your USER_HOME/.m2/settings.xmlto include the password.

    <settings>
        ...
        <servers>
            ...
            <server>
                <id>my-tomcat</id>
                <username>manager</username>
                <password>managerPwd</password>
            </server>
        </servers>
    
    </settings>
    
  4. Deploy using mvn tomcat7:redeploy

  1. 请更改您pom.xml的包含

    <project>
        ...
        <build>    
            <plugins>    
            ....
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <url>http://localhost:8080/manager/text</url>
                        <server>my-tomcat</server>
                        <path>/myapp</path>
                    </configuration>
                </plugin>
            </plugins>
            ...
        </build>
        ...
    </project>
    
  2. 确保您的 Tomcat 7 服务器上有以下几行TOMCAT_HOME/conf/tomcat-users.xml

    <!-- Role to manage WAR files via HTML /manager. The name should be as is! -->
    <role rolename="manager-gui"/>
    <!-- Role to manage WAR files via script like Maven. The name should be as is! -->
    <role rolename="manager-script"/>
    
    <!-- One user cannot have manager-gui and manager-script roles -->
    <user username="managerGui" password="managerPwd" roles="manager-gui"/>
    <user username="manager" password="managerPwd" roles="manager-script"/>
    
  3. 配置您USER_HOME/.m2/settings.xml以包含密码。

    <settings>
        ...
        <servers>
            ...
            <server>
                <id>my-tomcat</id>
                <username>manager</username>
                <password>managerPwd</password>
            </server>
        </servers>
    
    </settings>
    
  4. 部署使用 mvn tomcat7:redeploy

Read more on http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html

阅读更多关于http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html

回答by Naveen Sharma

A solution which worked in my case is:

在我的情况下有效的解决方案是:

  1. Go to the module having Main class.
  2. Right click on pom.xml under this module.
  3. Select "Run Maven" -> "UpdateSnapshots"
  1. 转到具有 Main 类的模块。
  2. 右键单击此模块下的 pom.xml。
  3. 选择“运行 Maven”->“UpdateSnapshots”

回答by user1565600

In my case solution worked. I did one petty mistake of not starting Apache Tomcat Server.

在我的情况下,解决方案有效。我犯了一个没有启动 Apache Tomcat 服务器的小错误。

Apart from this, make user that you do appropriate entry in maven/conf/setting.xml within tag:-

除此之外,让用户在标记中的 maven/conf/setting.xml 中进行适当的输入:-

<server>
    <id>TomcatServer</id>
    <username>admin</username>
    <password>password</password>
</server>

In Apache Tomcat 7 tomcat-users.xml, following line should be added within

在 Apache Tomcat 7 tomcat-users.xml 中,应在其中添加以下行

<tomcat-users>

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

In Pom.xml

在 Pom.xml 中

 <plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <url>http://localhost:8888/manager/text</url>
        <server>TomcatServer</server>
        <path>$ReplaceWithWarFileName$</path>
        <update>true</update>
        <username>admin</username>
        <password>password</password>
    </configuration>
</plugin>

回答by Olivier Bont

  1. A solution that worked for me was in the Run options :

    1_ Maven Install

    2_ Maven Build

  1. 一个对我有用的解决方案是在运行选项中:

    1_ Maven 安装

    2_ Maven 构建