i am using jjwt-0.9.1.jar and runtime gives this exception for jersey reset API call.
When i use this code using java main() method, its works perfectly but when i call from servlet to that class, the method throws exception.
import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import java.util.Date; import java.util.UUID; public String createJWTToken() { String id = UUID.randomUUID().toString().replace("-", ""); //The JWT signature algorithm we will be using to sign the token // SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; long nowMillis = System.currentTimeMillis(); Date now = new Date(nowMillis); //Let's set the JWT Claims JwtBuilder builder = null; try { builder = Jwts.builder().setId(id).setHeaderParam("typ", "JWT") .setIssuedAt(now) .setSubject("") .setIssuer(API_KEY) .signWith(SignatureAlgorithm.HS256,SECRET_KEY.getBytes("UTF-8")); //if it has been specified, let's add the expiration if (ttlMillis >= 0) { long expMillis = nowMillis + ttlMillis; Date exp = new Date(expMillis); builder.setExpiration(exp); } } catch (Exception e) { e.printStackTrace(); } return builder.compact();//Builds the JWT and serializes it to a compact, URL-safe string }
When call servlet to java class method i.e.createJWTToken() gives following exception in tomcat.
javax.servlet.ServletException: Servlet execution threw an exception at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:328) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.test.lms.servlets.GlobalFilter.doFilter(GlobalFilter.java:204) at com.test.lms.servlets.GlobalFilter.doFilter(GlobalFilter.java:48) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.general.FilterDemo.doFilter(FilterDemo.java:312) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:200) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.NoClassDefFoundError: io/jsonwebtoken/Jwts at com.zoom.JWTTokenGeneration.createJWTToken(JWTTokenGeneration.java:31) at com.zoom.Utilities.setMeeting(Utilities.java:571) at com.general.InsertController.doPost(InsertController.java:377) at javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) ... 22 more Caused by: java.lang.ClassNotFoundException: io.jsonwebtoken.Jwts at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546) ... 28 more
Advertisement
Answer
The exception is java.lang.NoClassDefFoundError: io/jsonwebtoken/Jwts
Check the Jar file(jwt) is packaged in the build or not?