user3021416
user3021416

Reputation: 1

sshj 0.9.0 throwing NoClassDefFoundError: net/schmizz/sshj/SSHClient

My code below is throwing following Error and only information i can find on Google involved logging errors but nothing that looks like mine. I have tried installing dependences it says are needed on the central maven repo but still the problem persists. Does anyone know why im getting class no found exceptions?

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.common.IOUtils;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Command;

public class ConnectSSH {

public void connecting() throws IOException {

    @SuppressWarnings("resource")
    final SSHClient ssh = new SSHClient();

    ssh.loadKnownHosts();
    ssh.connect("*******");

    try {
        ssh.authPassword("*****", "*****");
        final Session session = ssh.startSession();
        try {
            final Command cmd = session.exec("*****");
            System.out.print(IOUtils.readFully(cmd.getInputStream()));
            cmd.join(5, TimeUnit.SECONDS);
            System.out.print("\n** exit status: " + cmd.getExitStatus());
        } finally {
            session.close();
        }
    } finally {
        ssh.disconnect();

    }

}

}


Error below is thrown when running:

Exception in thread "main" java.lang.NoClassDefFoundError: net/schmizz/sshj/SSHClient
    at ssh.liq_con.stats.ConnectSSH.connecting(ConnectSSH.java:16)
    at ssh.liq_con.stats.App.main(App.java:8)
Caused by: java.lang.ClassNotFoundException: net.schmizz.sshj.SSHClient
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 2 more

Note i have:

<dependency>
            <groupId>net.schmizz</groupId>
            <artifactId>sshj</artifactId>
            <version>0.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.sshd</groupId>
            <artifactId>sshd-core</artifactId>
            <version>0.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpkix-jdk15on</artifactId>
            <version>1.49</version>
        </dependency>
        <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jzlib</artifactId>
            <version>1.1.3</version>
        </dependency>

Upvotes: 0

Views: 2363

Answers (1)

Andrey Chaschev
Andrey Chaschev

Reputation: 16526

You actually don't need to install dependencies - they are auto-fetched by Maven. This might be a problem with your classpath, you may try adding as the first line of your public static void main(String[]):

System.out.println(System.getProperty("java.class.path"));

to make sure you have sshj-0.9.0.jar in your classpath.

Upvotes: 1

Related Questions