【问题标题】:Fail to Maven Build due to an API incompatibility由于 API 不兼容,无法构建 Maven
【发布时间】:2023-03-12 13:09:01
【问题描述】:

我想使用 Servlet API 构建一个 maven 项目。但是,我失败了,错误出现了:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:3.0.0:war (default-war) on project myfirstservlet: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:3.0.0:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:3.0.0' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null

我对这个问题有点了解,但仍然不知道如何解决。我应该下载另一个版本的JDK、JRE或其他什么,或者只是重写我的代码? 这是我的 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.mavenservlet</groupId>
  <artifactId>myfirstservlet</artifactId>
  <properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>myfirstservlet 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>
     <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
    <scope>provided</scope>
</dependency>
    <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>javax.servlet.jsp-api</artifactId>
    <version>2.3.3</version>
    <scope>provided</scope>
</dependency>
  </dependencies>
  <build>
    <finalName>myfirstservlet</finalName>
    <plugins>
        <plugin>
            <groupId>com.mavenservlet</groupId>
            <artifactId>myfirstservlet</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.0.0</version>
                    <configuration>
            <webResources>
               <resource>
                  <directory>WebContent</directory>
               </resource>
            </webResources>
         </configuration>
                </plugin>
    </plugins>
  </build>
</project>

【问题讨论】:

  • 您是否将自己的 servlet 作为插件放入 POM 中?
  • 这就是我在pom.xml中尝试做的但是我失败了。我猜可能是不同版本的tomcat、jre、jdk等不兼容导致了这样的问题。
  • 我已经使用另一个代码完成了它,这花了我一些钱。这让我很困惑。我很乐意为追随者分享它。仍然感谢 J Fabian Meier 的真诚帮助@ J法比安·迈耶

标签: java eclipse api maven servlets


【解决方案1】:

这是正确的代码,但我花了一些钱。我仍然不知道它是如何工作的。但我很乐意与追随者分享它。

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mavenservlet</groupId>
    <artifactId>myfirstservlet</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.3</version>
        </dependency>

    </dependencies>

</project>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-04
    • 2018-06-27
    • 1970-01-01
    • 2014-06-25
    • 1970-01-01
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多