Maven - No plugin found for prefix 'tomcat7

2020-06-12 06:26发布

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

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

<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

标签: java maven
5条回答
再贱就再见
2楼-- · 2020-06-12 06:44

First, there is no start goal, see the goals page of 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 page of the plugin.

Here is a schematic structure of the pom.xml:

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

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

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

    <!-- ... -->
</project>
查看更多
一纸荒年 Trace。
3楼-- · 2020-06-12 06:49

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:

  <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.

查看更多
乱世女痞
4楼-- · 2020-06-12 06:53

This worked for me:

mvn clean install tomcat7:run
查看更多
▲ chillily
5楼-- · 2020-06-12 07:01

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

I saw that you don't have any pluginRepositories declared. Add the following lines to your 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>
查看更多
神经病院院长
6楼-- · 2020-06-12 07:04

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.xml file not works, try editing the settings.xml file at your .m2 directory this way:

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

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

查看更多
登录 后发表回答