java-jwt icon indicating copy to clipboard operation
java-jwt copied to clipboard

java.lang.NoClassDefFoundError: com/auth0/jwt/exceptions/JWTCreationException

Open sliceh opened this issue 5 years ago • 1 comments

Using 3.18.1 java-jwt library gives me NoClassDefError

NoClassDef Error for classes like Algorithm, JWT and JWTCreationException when i am trying to run the application

What was the expected behavior?

There should be no NoClassDefError

Reproduction

Detail the steps taken to reproduce this error, and whether this issue can be reproduced consistently or if it is intermittent. Note: If clear, reproducible steps or the smallest sample app demonstrating misbehavior cannot be provided, we may not be able to follow up on this bug report.

Where possible, please include:

  • private def createJWT(): String = { try { val algorithm = Algorithm.HMAC256(auditLogGatewayConfig.ebJwtSecret) JWT.create.withIssuer(auditLogGatewayConfig.issuer).withIssuedAt(new Date()).withSubject(auditLogGatewayConfig.subject) .withExpiresAt(expiry).withClaim("orgId", auditLogGatewayConfig.orgId).withClaim("admin", true) .sign(algorithm) } catch { case t: JWTCreationException => logger.warn("JWT token could not be created" + t) throw t } }
  • Log files (redact/remove sensitive information)
  • Application settings (redact/remove sensitive information)
  • Screenshots
  • Step 1..
  • Step 2..
  • ...

Environment

  • 3.18.1:
  • Scala - 2.12.12:
  • Other modules/plugins/libraries that might be involved:
  • Any other relevant information you think would be useful:

sliceh avatar Sep 14 '21 09:09 sliceh

I couldn't reproduce this running scala 2.12.12 and this library in version 3.18.1. At the end of this comment you can download this project:

Here is my snippet, adapted from what you shared above.

import java.util.Date

import com.auth0.jwt.JWT
import com.auth0.jwt.algorithms.Algorithm
import com.auth0.jwt.exceptions.JWTCreationException


object Main {

  def main(args: Array[String]) {
    val t = createJWT()
    println("Token: " + t)
  }

  private def createJWT(): String = {
    try {
      val algorithm = Algorithm.HMAC256("secret")
      JWT.create
        .withIssuer("myself")
        .withIssuedAt(new Date())
        .withSubject("user|123")
        .withExpiresAt(new Date(System.currentTimeMillis() + 1000 * 3600))
        .withClaim("orgId", "travel0")
        .withClaim("admin", true)
        .sign(algorithm)
    } catch {
      case t: JWTCreationException => println("JWT token could not be created" + t)
        throw t
    }
  }
}

Running the function main results in:

Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyfDEyMyIsImlzcyI6Im15c2VsZiIsImFkbWluIjp0cnVlLCJleHAiOjE2MzQ1NzIyOTIsImlhdCI6MTYzNDU2ODY5Miwib3JnSWQiOiJ0cmF2ZWwwIn0.fWVycRAIiz-FpfYFUbQMrtHC1Fz5My6j9ktU9c6tOUg

Process finished with exit code 0

The token can be seen here:

image

You can download my sample project from here: hello-token.zip

Closing for now, but if you can provide a sample like mine in which this doesn't compile, we can look into it. cc @jimmyjames

lbalmaceda avatar Oct 18 '21 14:10 lbalmaceda