[英]Error compilling Jetty embeded application : org.eclipse.jetty.server reads package jakarta.servlet from both jetty.servlet.api and jakarta.servlet
I'm bulding an embeded Jetty application with Maven. jetty.version: 11.0.13 servlet-api.version: 5.0.0.我正在构建一个带有 Maven 的嵌入式 Jetty 应用程序。jetty.version:11.0.13 servlet-api.version:5.0.0。
It is a multi module project.这是一个多模块项目。
One maven module, named "utils", depends on jakarta.servlet-api for compilling (scope is provided).一个名为“utils”的 maven 模块依赖于 jakarta.servlet-api 进行编译(范围已提供)。 The java module requires jakarta.servlet.
java 模块需要 jakarta.servlet。
// utils' pom.xml // 实用程序的 pom.xml
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
The maven "application" module adds the following dependencies and others. maven “应用程序”模块添加了以下依赖项和其他。
// application's pom.xml // 应用程序的 pom.xml
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
One of the other explicit dependency depends on the "utils" maven module.另一个显式依赖项之一取决于“utils”maven 模块。
The application's Java module contains:该应用程序的 Java 模块包含:
requires utils;
requires org.eclipse.jetty.http;
requires org.eclipse.jetty.server;
requires org.eclipse.jetty.servlet;
When I compile the application, all dependency modules compile OK but I get this error when compilling the last module (the application):当我编译应用程序时,所有依赖模块都编译正常,但在编译最后一个模块(应用程序)时出现此错误:
myapplication.BlaBla.java:[46,17] cannot access jakarta.servlet.http.HttpServlet class file for jakarta.servlet.http.HttpServlet not found myapplication.BlaBla.java:[46,17] 无法访问 jakarta.servlet.http.HttpServlet class 找不到 jakarta.servlet.http.HttpServlet 文件
If I add the following dependency:如果我添加以下依赖项:
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
and add the following line to my application's module:并将以下行添加到我的应用程序模块中:
requires jakarta.servlet;
My editor warns:我的编辑警告说:
Module 'application' reads package 'jakarta.servlet' from both 'jetty.servlet.api' and 'jakarta.servlet'模块“application”从“jetty.servlet.api”和“jakarta.servlet”中读取 package“jakarta.servlet”
And the build obviously fails with many error messages like:并且构建显然失败并出现许多错误消息,例如:
[ERROR] module org.eclipse.jetty.server reads package jakarta.servlet from both jetty.servlet.api and jakarta.servlet [ERROR] module org.eclipse.jetty.server reads package jakarta.servlet.http from both jetty.servlet.api and jakarta.servlet [ERROR] module org.eclipse.jetty.server reads package jakarta.servlet.descriptor from both jetty.servlet.api and jakarta.servlet [ERROR] module org.eclipse.jetty.server reads package jakarta.servlet.annotation from both jetty.servlet.api and jakarta.servlet [... [ERROR] module org.eclipse.jetty.server reads package jakarta.servlet from both jetty.servlet.api and jakarta.servlet [ERROR] module org.eclipse.jetty.server reads package jakarta.servlet.http from both jetty.servlet .api and jakarta.servlet [ERROR] module org.eclipse.jetty.server reads package jakarta.servlet.descriptor from both jetty.servlet.api and jakarta.servlet [ERROR] module org.eclipse.jetty.server reads package jakarta.来自 jetty.servlet.api 和 jakarta.servlet 的 servlet.annotation [...
If I look at the jetty.servlet.api jar file, I see no package named jakarta.servlet.如果我查看 jetty.servlet.api jar 文件,我看不到名为 jakarta.servlet 的 package。
I did notice that "jetty-jakarta-servlet-api-5.0.2.jar" contains the jakarta.servlet classes but I don't know to use this in my build process.我确实注意到“jetty-jakarta-servlet-api-5.0.2.jar”包含 jakarta.servlet 类,但我不知道在我的构建过程中使用它。
Help?帮助?
Seems like you are trying to get JPMS working with Jetty 11.似乎您正在尝试让 JPMS 与 Jetty 11 一起工作。
The requires jakarta.servlet;
requires jakarta.servlet;
and the error about "module <blah> reads package <blah> from both <foo1> and <foo2>"
tell me this.关于
"module <blah> reads package <blah> from both <foo1> and <foo2>"
的错误告诉我这个。
Here's what you need to know.这是您需要知道的。
The standard artifact for Jakarta Servlet 5.0.0 from Maven Central is... 来自 Maven Central 的 Jakarta Servlet 5.0.0的标准神器是...
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
</dependency>
This provides (in JPMS terms) the name jakarta.servlet
这提供了(在 JPMS 术语中)名称
jakarta.servlet
Look at the META-INF/MANIFEST.MF
in that file, you'll see the line查看该文件中的
META-INF/MANIFEST.MF
,您会看到该行
Automatic-Module-Name: jakarta.servlet
This dependency (unfortunately) isn't really well designed for JPMS due to...由于...,这种依赖性(不幸的是)并不是为 JPMS 设计的。
module-info.class
(this file is not present in the official dependency)module-info.class
(该文件不存在于官方依赖项中)jakarta.servlet
as an automatic-module-name.jakarta.servlet
声明为自动模块名称。 (basically reserving the name for later upgrade to a proper module-info.class
) module-info.class
)(BTW, the upcoming Jakarta Servlet 6.0 has fixed this). (顺便说一句,即将推出的 Jakarta Servlet 6.0 已经解决了这个问题)。
So why am I telling you this?那我为什么要告诉你这个?
Jetty was an early adopter of JPMS, and had to address some of the faults of Jakarta Servlet 5.0. Jetty 是 JPMS 的早期采用者,不得不解决 Jakarta Servlet 5.0 的一些缺陷。
One was the missing module-info.class
, another was the missing schemas (not present in the official Jakarta Servlet 5.0)一个是缺少的
module-info.class
,另一个是缺少的模式(官方 Jakarta Servlet 5.0 中不存在)
The replacement for jakarta.servlet
(the JPMS module name) version 5.0 when running a Jetty Server is...运行 Jetty 服务器时
jakarta.servlet
(JPMS 模块名称)版本 5.0 的替代品是......
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-jakarta-servlet-api</artifactId>
<version>5.0.2</version>
</dependency>
Use this when implementing a Jetty Server (like you are with your Embedded Jetty usage), and don't use the official dependency at all.在实现 Jetty 服务器时使用它(就像您使用嵌入式 Jetty 一样),并且根本不要使用官方依赖项。
The Jetty Jakarta Servlet API 5.0.2 has a module-info.class
with the following declaration. Jetty Jakarta Servlet API 5.0.2 有一个
module-info.class
声明如下。
module jetty.servlet.api {
exports jakarta.servlet;
exports jakarta.servlet.annotation;
exports jakarta.servlet.descriptor;
exports jakarta.servlet.http;
exports jakarta.servlet.resources;
//open resources so Class.getResource() can access them
opens jakarta.servlet.resources;
}
In the future, when you upgrade to Jetty 12 (currently in alpha releases), you can use the official jakarta.servlet
dependency.将来,当您升级到 Jetty 12(目前处于 alpha 版本)时,您可以使用官方的
jakarta.servlet
依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.