2017-06-07 8 views
0

Lorsque j'essaie d'utiliser JJWT de Stormpath, il lance une exception de temps d'exécution java.lang.ClassNotFoundException: io.jsonwebtoken.Jwts. J'utilise Jersey2 embarqué sur GlassFish 4.1; voici le code qui jette l'exception:java.lang.ClassNotFoundException: io.jsonwebtoken.Jwts lors de l'utilisation de JJWT JSON Web Token

private String issueToken(String login) { 
    Key key = keyGenerator.generateKey(); 
    //Key key = MacProvider.generateKey(); 
     String jwtToken = Jwts.builder() 
       .setIssuer(uriInfo.getAbsolutePath().toString()) 
       //.setIssuer("http://trustyapp.com/") 
       .setSubject(login) 
       .setIssuedAt(new Date()) 
       .setExpiration(toDate(LocalDateTime.now().plusMinutes(15L))) 
       .signWith(SignatureAlgorithm.HS512, key) 
       .compact(); 
     logger.info("#### generating token for a key : " + jwtToken + " - " + key); 
     return jwtToken; 
} 

J'ai importé io.jsonwebtoken.Jwts et mon pom.xml a:

<dependency> 
     <groupId>com.fasterxml.jackson.core</groupId> 
     <artifactId>jackson-annotations</artifactId> 
     <version>2.8.2</version> 
     <scope>compile</scope> 
    </dependency> 

J'ai aussi essayé sans la dépendance ci-dessus dans le cas où la ci-dessous la dépendance qui est sur mon pom.xml suffit:

<dependency> 
     <groupId>io.jsonwebtoken</groupId> 
     <artifactId>jjwt</artifactId> 
     <version>0.7.0</version> 
     <scope>compile</scope> 
    </dependency> 

J'ai essayé les recommandations de this et this mais il ne fonctionne pas, s'il vous plaît aider

Répondre

0

Le problème est résolu après avoir ajouté les dépendances suivantes dans mon pom.xml:

<dependency> 
     <groupId>org.glassfish.jersey.core</groupId> 
     <artifactId>jersey-common</artifactId> 
     <version>${version.jersey}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.glassfish.jersey.containers</groupId> 
     <artifactId>jersey-container-jdk-http</artifactId> 
     <version>${version.jersey}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.glassfish.jersey.core</groupId> 
     <artifactId>jersey-client</artifactId> 
     <version>${version.jersey}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.glassfish.jersey.core</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>${version.jersey}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.glassfish.jersey.containers</groupId> 
     <artifactId>jersey-container-servlet</artifactId> 
     <version>${version.jersey}</version> 
    </dependency> 

Je suppose que ces dépendances ne sont pas nécessaires puisque j'utilise Jersey 2 qui est intégré sur le GlassFish4.1.1 Server.