【问题标题】:Maven - No plugin found for prefix 'tomcat7' in the current projectMaven - 在当前项目中找不到前缀“tomcat7”的插件
【发布时间】:2014-01-31 03:02:15
【问题描述】:

我创建了一个原型为“webapp”的 Maven 项目,但是当我启动命令“mvn tomcat7:start”时,出现以下错误:

No plugin found for prefix 'tomcat7' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\dark\.m2\repository), central (http://repo.maven.apache.org/maven2)] -> [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.

我的项目结构:

-src 
   -main
       -resources
       -webapp
          -WEB-INF
             -web.xml
          -index.jsp
-target
    -classes
    -dependency
        - // the 'dependency' directory contains all the jar files
    -lbagno
    -maven-archiver
    -surefire
    lbagno.war

我的 pom.xml 包含对 tomcat 的依赖。

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

 <modelVersion>4.0.0</modelVersion>
 <groupId>com.myspace</groupId>
 <artifactId>lbagno</artifactId>
 <packaging>war</packaging>
 <version>0.0.1-SNAPSHOT</version>
 <name>lbagno Maven Webapp</name>
 <url>http://maven.apache.org</url>


 <dependencies>
     <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
         <scope>test</scope>
     </dependency>

     <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-core</artifactId>
         <version>3.1.0.RELEASE</version>
     </dependency>

     <dependency>
         <groupId>org.apache.tomcat.maven</groupId>
         <artifactId>tomcat7-maven-plugin</artifactId>
         <version>2.2</version>
         <type>maven-plugin</type>
     </dependency>
 </dependencies>

 <build>
    <finalName>lbagno</finalName>
 </build>

</project>

我不明白为什么它不起作用。

你有什么解决办法吗?

谢谢

【问题讨论】:

    标签: java maven


    【解决方案1】:

    我知道它是在一年前提出的,但我的答案可能对我以外的其他人有用。

    如果在pom.xml 文件中创建构建标记不起作用,请尝试以这种方式在您的.m2 目录中编辑settings.xml 文件:

    <pluginGroups>
      ...
      <pluginGroup>org.apache.tomcat.maven</pluginGroup>
      ...
    </pluginGroups>
    

    我在这里找到了解决方案: http://tomcat.apache.org/maven-plugin-2.2/

    【讨论】:

    • 几个月来我一直使用pom.xml(如@RC)声明将我的Maven项目部署到Tomcat没有问题,但突然间,没有明显的变化,它坏了。你的解决方案让它再次部署。
    • 为什么将其添加到 settings.xml 是一种特殊情况?
    • 这为我解决了这个问题。这是正确的答案
    【解决方案2】:

    首先,没有起始目标,看文档的goals page

    接下来,它是一个插件,你声明它是一个依赖,这就是为什么你得到这个错误,我建议你阅读插件的usage page

    下面是pom.xml的示意结构:

    <project>
        <!-- ... -->
    
        <dependencies>
            <!-- your deps here -->
        </dependencies>
    
        <build>
            <plugins>
                <!-- your default build plugins here -->
            </plugins>
        <build>
    
        <!-- ... -->
    </project>
    

    【讨论】:

      【解决方案3】:

      这对我有用:

      mvn clean install tomcat7:run
      

      【讨论】:

        【解决方案4】:

        使用 -X -e 参数运行 mvn。这应该会为您提供有关错误的更多信息。

        我看到您没有声明任何pluginRepositories。将以下行添加到您的 pom.xml:

        <pluginRepositories>
            <pluginRepository>
                <id>apache.snapshots</id>
                <name>Apache Snapshots</name>
                <url>http://repository.apache.org/content/groups/snapshots-group/</url>
                <releases>
                    <enabled>false</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
        

        【讨论】:

          【解决方案5】:

          尝试从你的依赖中删除这部分,并将这行代码放在你项目 pom.xml 的插件中。 从依赖中删除这行代码:

            <dependency>
               <groupId>org.apache.tomcat.maven</groupId>
               <artifactId>tomcat7-maven-plugin</artifactId>
               <version>2.2</version>
               <type>maven-plugin</type>
           </dependency>
          

          然后把它放在 ....

          <plugin>
              <groupId>org.apache.tomcat.maven</groupId>
              <artifactId>tomcat7-maven-plugin</artifactId>
              <version>2.2</version>
          </plugin>
          

          这肯定会奏效。

          【讨论】:

            猜你喜欢
            • 2014-08-10
            • 2015-08-31
            • 2017-06-02
            • 2015-02-28
            • 2023-03-04
            • 2021-05-31
            • 2020-06-24
            • 2018-04-28
            • 2016-07-09
            相关资源
            最近更新 更多