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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21073123/
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-13 06:24:07  来源:igfitidea点击:

Maven - No plugin found for prefix 'tomcat7' in the current project

javamaven

提问by user2274060

I've created a Maven project with the archetype "webapp" but when I start the command "mvn tomcat7:start", I've the following error :

我已经使用原型“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.

My project structure :

我的项目结构:

-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

My pom.xml contains well the dependency for tomcat.

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

pom.xml

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>

I don't understand why it doesn't work.

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

Do you have any solutions ?

你有什么解决方案 ?

Thank you

谢谢

回答by user2274060

First, there is no start goal, see the goals pageof the doc.

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

Next, it's a plugin, you declared it as a dependency, this is why you get this error, I suggest you read the usage pageof the plugin.

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

Here is a schematic structure of the pom.xml:

下面是一个结构示意图pom.xml

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

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

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

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

回答by Seitaridis

Run mvn with -X -eparams. This should give you more information about the error.

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

I saw that you don't have any pluginRepositoriesdeclared. Add the following lines to your pom.xml:

我看到你没有任何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>

回答by Diego Magdaleno

I know it was asked a year ago, but my answer might work for somebody other than me.

我知道一年前有人问过这个问题,但我的回答可能适用于我以外的其他人。

If creating the build tag in the pom.xmlfile not works, try editing the settings.xmlfile at your .m2 directory this way:

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

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

I found the solution here: http://tomcat.apache.org/maven-plugin-2.2/

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

回答by Rail Yulgutlin

This worked for me:

这对我有用:

mvn clean install tomcat7:run

回答by AlokeT

Try to delete this part from your dependency and put this line of code in plugins on your projects pom.xml. From dependency delete this line of codes:

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

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

and put this in ....

并将其放入....

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

This will surely work.

这肯定会奏效。