【发布时间】:2019-10-06 02:54:36
【问题描述】:
我对 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 版本。
非常感谢任何帮助,我看到了一些关于 exclusion 的信息
标签,但甚至不知道该放在哪里,因为它看起来不像 pom.xml 中的任何东西都在要求这个 jar。
【问题讨论】:
-
您可以使用
mvn dependency:tree打印依赖关系及其临时依赖关系。您的依赖项之一很可能依赖于旧版本的 servlet-api,这就是您遇到冲突的原因。您可以按照此处的说明为该依赖项添加排除项:maven.apache.org/plugins/maven-resources-plugin/examples/… -
感谢您的评论。这就是我的想法,但我正在使用 m2e 并且不知道如何使用命令行加上我的终端窗口在我的 eclipse 上不起作用
-
@Babyburger 你提供给我的链接也排除了一个文件而不是下载的依赖项。有什么方法可以用 eclipse 找出需要旧版本 servlet 的依赖项。非常感谢提前
-
如果您在 Eclipse 中的终端窗口不工作,您需要重新安装 Eclipse。如果没有 Eclipse 中的控制台窗口,您将无法正确使用 Maven。
-
不久之前我重新安装了它,但它说
Could not create the view: org.eclipse.tm.terminal.view.ui.TerminalsView
标签: java eclipse maven google-app-engine