0
votes

I am using JSch to SFTP files to my server.

In Rational Application Developer (RAD) all works as expected.

Outside of RAD, running via bat file I am connecting to SFTP server without any issues but when trying to create directory I am getting following error message:

com.jcraft.jsch.JSchException: Session.connect: java.security.NoSuchAlgorithmException: DH KeyPairGenerator not available

What do I have in my RAD jdk that I don't have on my machine when running it via bat file? Obviously, it can create connection so my bat file can access jsch-0.1.51.jar but it is missing some other jar in my C:\Progra~1\Java\jre6\bin that is include in RAD jre.

2

2 Answers

1
votes

Are you sure that

  • Your JDK has one of the JAR files (see below) that contain the KeyPairGenerator class?
    I documented what JAR files contain this class below.
  • The CLASSPATH is set to include the path to one of the above JAR files?
  • Your JAVA_HOME is set ?

According to findJAR.com, the KeyPairGenerator class is contained in these JAR files:

rt.jar
org.osgi.foundation-1.0.0.jar
org.osgi.foundation-1.2.0.jar

I searched for rt.jar:

  • The rt.jar file is in my ANT lib directory.
  • The rt.jar file is also in the jre/lib subdirectory of my JDK directory.

If you don't have a containing JAR file anywhere, then try adding the ANT lib directory to your CLASSPATH.


This test ANT project can be used to verify SSH is working:

    <?xml version="1.0" encoding="windows-1252" ?>
    <project name="ServerSSH" default="dist" basedir=".">
      <target name="dist">
        <echo message="TEST BEGINNING"></echo>
        <sshexec host="svr1"
                 username="user1"
                 description="Test connection"
                 keyfile="c:/.ssh/id_rsa"
                 trust="true"
                 command="echo CONNECTION SUCCESS FOR SERVER SVR1"
                 failonerror="true"/>

        <echo message="TEST END"></echo>

      </target>

    </project>

This test can be invoked as follows:

    set JAVA_HOME=c:\progra~1\Java\jdk1.7.0_21
    set ANT_HOME=C:\ant
    set ANTLIB=c:\ant\lib
    set PATH=%ANT_HOME%\bin;%ANT_HOME%\lib;
    ant -d -lib %ANTLIB% dist -f SSHTEST.xml

By running a test, you can verify whether SSH for JAVA will work outside of the project.

1
votes

And the answer is: Be careful when setting java.ext.dirs to include your JARs

http://peterttseng.blogspot.com/2008/09/be-careful-when-setting-javaextdirs-to.html