Caused by: java.lang.NoClassDefFoundError: io/jsonwebtoken/Jwts

Caused by: java.lang.NoClassDefFoundError: io/jsonwebtoken/Jwts

我正在使用 jjwt-0.9。1.jar 并且运行时为球衣重置 API 调用提供了此异常。

当我使用 java main() 方法使用这段代码时,它工作得很好,但是当我从 servlet 调用那个 class 时,该方法抛出异常。

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
    }

当调用 servlet 到 java class 方法时 i.e.createJWTToken() 在 tomcat.[=20 中给出以下异常=]

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

例外情况是 java.lang.NoClassDefFoundError:io/jsonwebtoken/Jwts

检查 Jar 文件(jwt) 是否打包在构建中?