HTTP Status 500 - Provider org.glassfish.json.JsonProvider找不到

2022-09-03 03:27:43

我正在使用我创建了一个webapp并将api添加到我的项目中,代码显示没有错误,但是当我运行我的servlet时,会发生以下错误。netbeans-8, jdk 7,tomcat 8.05.netbeansjavax.json

HTTP Status 500 - Provider org.glassfish.json.JsonProviderImpl not found

type Exception report

message Provider org.glassfish.json.JsonProviderImpl not found

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found
    javax.json.spi.JsonProvider.provider(JsonProvider.java:97)
    javax.json.Json.createObjectBuilder(Json.java:266)
    NewServlet.doGet(NewServlet.java:24)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause

java.lang.ClassNotFoundException: org.glassfish.json.JsonProviderImpl
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1284)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1132)
    java.lang.Class.forName0(Native Method)
    java.lang.Class.forName(Class.java:190)
    javax.json.spi.JsonProvider.provider(JsonProvider.java:94)
    javax.json.Json.createObjectBuilder(Json.java:266)
    NewServlet.doGet(NewServlet.java:24)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.3 logs.

Apache Tomcat/8.0.3

答案 1

javax.json api(在 JSON Processing API jar 中提供)仅适用于编译应用程序。

如果要运行应用程序,则必须下载 JSON Processing RI jar,如下所述:https://jsonp.java.net/download.html

JSON Processing RI jar 包含您缺少的 org.glassfish.json.JsonProviderImpl 类。


答案 2

这个答案中,你可以用它的org.glassfish实现来取代javax.json依赖关系。

Maven repo, 提供:

<dependency>
  <groupId>org.glassfish</groupId>
  <artifactId>javax.json</artifactId>
  <version>1.0.4</version>
</dependency>