I am creating a REST API in Java with Jersey and Maven. I used Tomcat 9 as my server. Everything worked fine until I tried installing RestAssured, Hamcrest, and JUnit . Suddenly, all my endpoints threw 500 internal server errors. The root cause of error 500 isjava.lang.NoClassDefFoundError: org/glassfish/jersey/internal/inject/Binder.
What I did is 2 hours:
- I tried to find this class:
org/glassfish/jersey/internal/inject/Binder
on google, but to no avail. - I tried to remove RestAssured , Hamcrest and JUnit , but that did not help.
This problem makes me upset. Any idea why these errors occurred? Thanks in advance!
Here is an excerpt from the server log:
SEVERE: Throw exception for servlet jersey web application java.lang.ClassNotFoundException: org.glassfish.jersey.internal.inject.Binder in org.apache.catalina.loader.WebappClassLoaderBase.loadClass (WebappClassLoaderBase.java:1275) in org.apache.catalina.loader.WebappClassLoaderBase.loadClass (WebappClassLoaderBase.java:1109) at org.glasslet.jlet.sj (ServletContainer.java:178) at org.glassfish.jersey.servlet.ServletContainer.init (ServletContainer.javahaps70) at javax.servlet.GenericServlet.init (GenericServlet.java:158) at org.apache.catalina.core. StandardWrapper.initServlet (StandardWrapper.java:1183) at org.apache.catalina.core.StandardWrapper.loadServlet (StandardWrapper.java:1099) at org.apache.catalina.core.StandardWrapper.allocate (StandardWrapper.java:779) at org .apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java:133) at org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java: 96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java:475) on org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java:140) on org.apache.catalina.valves .ErrorReportValve.invoke (ErrorReportValve.java:80) at org.apache.catalina.valves.AbstractAccessLogValve.invoke (AbstractAccessLogValve.java:624) on org.apache.catalina.core.StandardEngineValve.invoke (StandardEng org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.javahaps41) at org.apache.coyote.http11.Http11Processor.service (Http11Processor.java:498) at org.apache.coyote.AbstractProcessorLight.process (AbstractProcessorL java: 66) at org.apache.coyote.AbstractProtocol $ ConnectionHandler.process (AbstractProtocol.java:796) at org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun (NioEndpoint.java:1368) at org.apache.tomcat.util.net.SocketProcessorBase.run (SocketProcessorBase.java:49) in java.util.concurrent.ThreadPoolExecutor.runWorker (Unknown source) in java. util.concurrent.ThreadPoolExecutor $ Worker.run (Unknown source) at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run (TaskThread.java:61) in java.lang.Thread.run (Unknown source)run (Unknown source)run (Unknown source)
pom.xml
: ( RestAssured, Hamcrest JUnit)
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
web.xml:
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.accelbyte.vincent.emailist.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
: