HTTP Status 500 - java.lang.NoClassDefFoundError:

2019-02-22 04:34发布

I'm learning about RESTFUL Webservice, i'm building a simply app on free host of OpenShift

my server and db on OpenShift : jbossews-2.0 (Tomcat 7); postgresql-9.2 This is my Java build path This is my lib

When I test at localhost I don't get errors, but when I run the application on OpenShift Host I see on the page:

HTTP Status 500 - java.lang.NoClassDefFoundError: java/time/temporal/TemporalField

type Exception report

message java.lang.NoClassDefFoundError: java/time/temporal/TemporalField

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

exception

javax.servlet.ServletException: java.lang.NoClassDefFoundError: java/time/temporal/TemporalField
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

java.lang.NoClassDefFoundError: java/time/temporal/TemporalField
    org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:320)
    org.postgresql.Driver.makeConnection(Driver.java:406)
    org.postgresql.Driver.connect(Driver.java:274)
    java.sql.DriverManager.getConnection(DriverManager.java:571)
    java.sql.DriverManager.getConnection(DriverManager.java:215)
    service.TestService.main(TestService.java:126)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:606)
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

java.lang.ClassNotFoundException: java.time.temporal.TemporalField
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:320)
    org.postgresql.Driver.makeConnection(Driver.java:406)
    org.postgresql.Driver.connect(Driver.java:274)
    java.sql.DriverManager.getConnection(DriverManager.java:571)
    java.sql.DriverManager.getConnection(DriverManager.java:215)
    service.TestService.main(TestService.java:126)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:606)
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

PS: I changed file postgresql-9.4.1208.jar (for jdk 8) into prostgresql-9.4.1208.jre7.jar (for jdk 7) in my WEB-INF lib, and now everything worked well. Thanks everybody so much ! Have a good time !!!

3条回答
Rolldiameter
2楼-- · 2019-02-22 04:36

According to Java docs the time/temporal/TemporalField was introduced on version 1.8

I created a Tomcat 7 (JBoss EWS 2.0) Cartridge and checked the version:

$ ssh $MY_APP
$ java -version
java version "1.7.0_95"
查看更多
Evening l夕情丶
3楼-- · 2019-02-22 04:38

Changing to 9.4.1208.jre7 resolved my problem, it seems they compiled it for jdk8

查看更多
forever°为你锁心
4楼-- · 2019-02-22 04:49

In my case (Tomcat 8 on SLES 11.3) it turned out that although I had installed Java 8 SDK without uninstalling Java 7, and set JAVA_HOME accordingly, JRE_HOME was still pointing to my Java 7 installation. Fixing that resolved the problem.

查看更多
登录 后发表回答