user234194
user234194

Reputation: 1723

issue while ssh while using sshj in java

I am trying to get a remote connection to server to execute some commands. I am new to this so started googling. After some search, I gave a try:

I am using sshj0.2.3.jar.

And here is how I implemented it:

public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    final SSHClient ssh = new SSHClient();
    ssh.loadKnownHosts();
    ssh.connect("serverName");
    try{
        ssh.authPublickey("myUserId");
        final Session session = ssh.startSession();
        try{
            final Command cmd = session.exec("net send myMachineName Hello!!!");
            System.out.println(cmd.getOutputAsString());
            System.out.println("\n Exit Status: "+cmd.getExitStatus());
        }finally{
            session.close();
        }
        }finally{
            ssh.disconnect();
        }   
    }

}

But I get the folowing exception:

    Exception in thread "main" java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
    at net.schmizz.sshj.DefaultConfig.(DefaultConfig.java:92)
    at net.schmizz.sshj.SSHClient.(SSHClient.java:133)
    at SSHTEST.main(SSHTEST.java:24)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:419)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:643)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:345)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:609)
    .....

Do I need extra jars,How many extra jars do i need. Am I implementing correctly?. please help.

Thanks in advance.

Upvotes: 2

Views: 4284

Answers (3)

shikhar
shikhar

Reputation: 2492

slf4j is just a facade, and you need to supply a concrete implementation. If you don't really care about logging, stick in slf4j-nop-$(ver).jar that is present in the slf4j distribution.

Upvotes: 1

Peter Tillemans
Peter Tillemans

Reputation: 35331

Yes, you need the jars for slf4j (see the 2-page manual)

slf4j comes with a API and then a pluggable implementation, but the proposed slf4j-simple should be just fine

Upvotes: 2

Chris Bunch
Chris Bunch

Reputation: 89823

From googling sshj, the first result reveals the answer:

Dependencies

Java 6+. slf4j is required. bouncycastle is highly recommended and required for using some of the crypto algorithms. jzlib is required for using zlib compression.

Upvotes: 3

Related Questions