Maven - 在当前项目中找不到前缀'tomcat7'的插件

use*_*060 9 java maven

我用原型"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.
Run Code Online (Sandbox Code Playgroud)

我的项目结构:

-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
Run Code Online (Sandbox Code Playgroud)

我的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>
Run Code Online (Sandbox Code Playgroud)

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

你有什么解决办法 ?

谢谢

Die*_*eno 9

我知道一年前有人问过,但我的回答可能对我以外的人有用.

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

<pluginGroups>
  ...
  <pluginGroup>org.apache.tomcat.maven</pluginGroup>
  ...
</pluginGroups>
Run Code Online (Sandbox Code Playgroud)

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


小智 2

首先,没有起始目标,请参阅文档的目标页面。

接下来,它是一个插件,您将其声明为依赖项,这就是您收到此错误的原因,我建议您阅读该插件的使用页面。

这是一个示意性结构pom.xml

<project>
    <!-- ... -->

    <dependencies>
        <!-- your deps here -->
    </dependencies>

    <build>
        <plugins>
            <!-- your default build plugins here -->
        </plugins>
    <build>

    <!-- ... -->
</project>
Run Code Online (Sandbox Code Playgroud)