2017-07-24 2 views
0

J'utilise ci-dessous méthode pour se connecter à l'hôte distant et exécuter la commande en utilisant JSch:NoClassDefFoundError SecretKeySpec avec JSch

public String runCommandOnRemote(String username, String password, String hostname, String command) { 
    String output = null; 
    JSch jsch = new JSch(); 
    java.util.Properties config = new java.util.Properties(); 
    config.put(Constants.STRICT_HOST_KEY_CHECKING, Constants.STRICT_HOST_KEY_CHECKING_NO); 
    Session session; 
    try { 
     session = jsch.getSession(username, hostname); 
     session.setPassword(password); 
     session.setConfig(config); 
     session.connect(30000); 
     ChannelExec channel = (ChannelExec) session.openChannel(Constants.CHANNEL_EXEC); 
     BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(channel.getInputStream())); 
     ((ChannelExec) channel).setCommand(command); 
     channel.setCommand(command); 
     channel.connect(3 * 1000); 
     while ((output = bufferedReader.readLine()) != null) { 
     } 
     channel.disconnect(); 
     session.disconnect(); 
     return output; 
    } catch (JSchException | IOException e) { 
     new InstanceException("Error connecting to remote host" + hostname + ". " + e.getMessage()); 
     logger.error("Error connecting to remote host " + hostname + "\n" + e.getMessage()); 
     e.printStackTrace(); 
    } 

Sur session.connect(), il donne ci-dessous erreur:

[err] Exception in thread "Thread-57" 
[err] java.lang.NoClassDefFoundError: javax/crypto/spec/SecretKeySpec 
[err] at com.jcraft.jsch.jce.AES256CTR.init(AES256CTR.java:55) 
[err] at com.jcraft.jsch.Session.checkCipher(Session.java:2497) 
[err] at com.jcraft.jsch.Session.checkCiphers(Session.java:2474) 
[err] at com.jcraft.jsch.Session.send_kexinit(Session.java:624) 
[err] at com.jcraft.jsch.Session.connect(Session.java:307) 

La classe SecretKeySpec est fournie dans jce.jar dans le cadre de la bibliothèque système JRE. Alors pourquoi ai-je cette erreur?

+0

Copie possible de [Pourquoi le package javax.crypto n'existe pas] (https://stackoverflow.com/questions/14935447/why-am-i-getting-package-javax-crypto-does-not- exister) – araknoid

Répondre

0

C'était un projet OSGi et j'ai dû ajouter la dépendance dans le fichier manifeste.