简体   繁体   中英

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.

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM