【发布时间】:2021-09-09 06:47:19
【问题描述】:
我想了解如何使用 JAX-RS 开发 RESTful API,因此我从一个 YouTube 视频中介绍的示例开始。该视频创建于 5 -6 年前,使用 Tomcat 7 和旧版本的 Eclipse。但我安装了最新版本的 Tomcat (10.0.6) 和 Eclipse (jee-2021-03) 并按照教程进行操作。
我使用以下原型创建了一个新的 maven 项目: 组 ID:org.glassfish.jersey.archetypes 工件 ID:jersey-quickstart-webapp 版本:3.0.2
我为我的项目提供了默认版本 0.0.1-SNAPSHOT 的 Group Id 和 Artifact Id,然后单击 Finish。
Eclipse 创建项目时出现以下 2 个错误:
- index.jsp:“在 Java 构建路径中找不到超类“javax.servlet.http.HttpServlet””
- pom.xml:“无法初始化类 org.apache.maven.plugin.war.util.WebappStructureSerializer”在第一行。
如果有人能帮助我了解为什么会出现这些错误以及如何解决这些错误,我将不胜感激。
这是我的 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.xyz.rest</groupId>
<artifactId>onlineshopping</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>onlineshopping</name>
<build>
<finalName>onlineshopping</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<!-- uncomment this to get JSON support
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>
-->
</dependencies>
<properties>
<jersey.version>3.0.2</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
【问题讨论】:
-
这有点难说。也许您应该从不同的教程开始:howtodoinjava.com/spring-boot/spring-boot-jersey-example。
-
感谢 David 推荐另一个教程。但我想完成我的教程,因为我看了几部同一个人的理论视频,我喜欢他的系列。但是看到这个错误令人沮丧。您能否建议一些我可以尝试的事情,或者董事会上可以提供帮助的人?