首页 > 解决方案 > 如何在 Eclipse 中删除 maven 依赖 jar

问题描述

我对 Maven 非常陌生,只是将我的应用程序引擎项目转换为 Maven 项目。我在pom.xml文件中添加了依赖项以消除错误。但现在我进入我的代码

HttpServletRequest 类型的方法 getPart(String) 未定义

因此,在对 Stack Overflow 进行了一些研究之后,看来我需要一个更新的软件包servlet-api才能使其正常工作。

显然,我可能与我的 Maven 依赖项中的旧版本发生冲突,但我从未将它添加到其中pom.xml,现在我被这个 jar 卡住了,不知道为什么要导入它以及如何删除它。

这是我的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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>my-project</groupId>
  <artifactId>my-project</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.1</version>
            <configuration>
                 <webResources>
                    <resource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                    </resource>
                </webResources>
            </configuration>
      </plugin>
      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>appengine-maven-plugin</artifactId>
         <version>1.3.1</version>
            <configuration>
                 <deploy.promote>true</deploy.promote>
                <deploy.stopPreviousVersion>true</deploy.stopPreviousVersion>
            </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
    <dependency>
        <groupId>com.mailjet</groupId>
        <artifactId>mailjet-client</artifactId>
        <version>4.2.1</version>
    </dependency>
    <dependency>
        <groupId>com.google.appengine.tools</groupId>
        <artifactId>appengine-gcs-client</artifactId>
        <version>0.8</version>
    </dependency>
  </dependencies>
  <properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>

这是我Maven dependencies在构建路径中获得的图像。

我的猜测是错误来自 servlet-api 的 2.5 版本。

构建路径部分 最终与 servlet-api 2.5 和 3.1 发生冲突

所以非常感谢任何帮助,我看到了一些关于exclusion 标签的东西,但甚至不知道把它放在哪里,因为它看起来不像pom.xml是在要求这个罐子里的任何东西。

标签: javaeclipsemavengoogle-app-engine

解决方案


您最好在 Eclipse 中打开您的 pom.xml 文件并切换到“依赖层次”选项卡。查找不需要的库(在过滤器中输入“serlvet”)并通过上下文菜单在其上添加排除项。这将修改您的 pom.xml 文件。


推荐阅读