Java 6: NoClassDefFoundError: com.nimbusds.jose.crypto.MACSigner (initialization failure)

Issue #446 closed
Rubén Luna created an issue

Hi, I am working on a Project in Java 1.6 and server application websphere 8.5.5, I need to do an implementation with JWT and I decided to use your library because I read in your website that it works with Java 6 (https://connect2id.com/blog/jwt-with-java-6). I imported the libraries to the server, specifically WEB-INF/LIB but I am having the following problem:

Caused by: java.lang.NoClassDefFoundError: com.nimbusds.jose.crypto.MACSigner (initialization failure)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:175)

Caused by: java.lang.NoClassDefFoundError: net.minidev.json.JSONAware
at java.lang.ClassLoader.defineClassImpl(Native Method)

If I added both libraries in the server, why does it have an error? Should I add anything else? Or could it be a compatibility or version error?

I drop here the dependencies and the code.

<dependency>
    <groupId>com.nimbusds</groupId>
    <artifactId>nimbus-jose-jwt</artifactId>
    <classifier>jdk16</classifier>
    <version>5.14</version>
</dependency>
<dependency>
    <groupId>net.minidev</groupId>
    <artifactId>json-smart</artifactId>
    <version>1.3.1</version>
</dependency>
protected String crearJWT( String issuer, Date exp , String secret ) throws CrearJwtMicroservicioException
{
    escribirEntradaLogDebug( this.getClass() );

    String jwt = "";

    try
    {
        JWSSigner signer = new MACSigner( secret );

        JWSHeader header = new JWSHeader( JWSAlgorithm.HS256, JOSEObjectType.JWT , null, null, null,
                null, null, null, null, null, null, null,
                null);

        JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
                .issuer( issuer )
                .expirationTime( exp )
                .build();

        SignedJWT signedJWT = new SignedJWT( header, claimsSet );
        signedJWT.sign( signer );
        jwt = signedJWT.serialize();
    }
    catch ( KeyLengthException e )
    {
        logger.error( "excepcion {} procesada : {}", e.getClass().getSimpleName(), e.getMessage() );
        throw new CrearJwtMicroservicioException( e );
    }
    catch ( JOSEException e )
    {
        logger.error( "excepcion {} procesada : {}", e.getClass().getSimpleName(), e.getMessage() );
        throw new CrearJwtMicroservicioException( e );
    }
    catch ( Exception e )
    {
        logger.error( "excepcion {} procesada : {}", e.getClass().getSimpleName(), e.getMessage() );
        throw new CrearJwtMicroservicioException( e );
    }

    escribirSalidaLogDebug( this.getClass() );
    return PropiedadesTransaccional.obtenerPropiedad( PropiedadesTransaccional.HTTP_AUTHENTICATION_SCHEME ) + jwt;
}

Note: in local that works

Comments (7)

  1. Vladimir Dzhuvinov

    Hi Ruben,

    My recollection from 2016 is that the Java 6 support was a contribution, but it wasn’t well maintained and tested as such afterwards.

    I suggest to rebuild the code using a Java 6 compiler. Also double check that JSON Smart in version 1.3.1 is indeed built for Java 6.

  2. Rubén Luna Account Deactivated reporter

    Hi Vladimir! Thank you for your answers

    Ok, I will check that the library I added to the server is the correct version

    I suggest to rebuild the code using a Java 6 compiler. Also double check that JSON Smart in version 1.3.1 is indeed built for Java 6.

    I meant that when I test this code in my local environment (on my computer) it works (I have java 1.6 configured as well)

    PS: I didn’t understand that sentence:


    Acutalization

    I have checked the library and it is the correct version, but the error persists, could it be because the Nimbus library does not try to look for the net.minidev library on the server? When I started using the Nimbus library, I didn't know that I needed that net.minidev library until I realized that when I compiled it was downloaded, that's when I decided to add it to the pom and grab the library. But I don't understand why the server doesn't take that other library at runtime.

  3. Rubén Luna Account Deactivated reporter

    Since I didn't get a solution and I have to stick to a development time, I decided to use another library. But the problem was not solved.

  4. Vladimir Dzhuvinov

    There are not plans to revert Java 6 support in future, so we’ll leave it at that.

    Best with with your project!

  5. Rubén Luna Account Deactivated reporter

    I understand, it is too old technology. I hope they are encouraged to migrate to java 8 at least, it really is a headache to work with java 6.

    Thanks for your time and answers! 👍

  6. Log in to comment