Java运行SSHD服务器时出错 – 找不到类定义

huangapple go评论69阅读模式
英文:

Java run SSHD Server Error - No class def found

问题

我目前正在运行一个Java Mina SSHD服务器。
我之前使用sshd-core-0.14.0版本成功运行了我的服务器,但我的病毒扫描器标记了弱密码,没有其他选择,只能升级到版本2.5.1。我尝试简单地替换.jar文件并将classpath变量更改为新版本,但出现以下错误。

错误: 发生了JNI错误,请检查您的安装并重试
主线程中的异常"java.lang.NoClassDefFoundError: org.apache.sshd.commo
n.KeyPairProvider
        at java.lang.J9VMInternals.prepareClassImpl(Native Method)
        at java.lang.J9VMInternals.prepare(J9VMInternals.java:303)
        at java.lang.Class.getMethodHelper(Class.java:1247)
        at java.lang.Class.getMethod(Class.java:1191)
        at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:556
)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:538)
Caused by: java.lang.ClassNotFoundException: org.apache.sshd.common.KeyPairProvi
der
        at java.net.URLClassLoader.findClass(URLClassLoader.java:610)
        at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:944)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:889)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:872)
        ... 6 more

启动基于Java的SSHD的代码在这里:

import org.apache.sshd.SshServer;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WinSSHServer {
    public WinSSHServer(Properties props) throws IOException {
        final SshServer sshd = SshServer.setUpDefaultServer();

        sshd.getProperties().put(SshServer.IDLE_TIMEOUT, String.valueOf(sessionTimeoutMSec));
        sshd.setPort(22);
        sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(props.getProperty("hostkey")));
        sshd.setCommandFactory(new WinCmdExeCommandFactory());

        final PuTTYPublicKeyAuthenticator pka = new PuTTYPublicKeyAuthenticator();
        addPublicKeysFromProps(pka, props);
        sshd.setPublickeyAuthenticator(pka);

        sshd.start();
    }
}
英文:

I am currently running a Java Mina SSHD server.
I had my server running fine with sshd-core-0.14.0 but my virus scanner was flagging weak ciphers leaving me no choice but to upgrade to version 2.5.1. I have tried simply replacing the .jar files and changing the classpath vars to the new versions but get the following error.

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org.apache.sshd.commo
n.KeyPairProvider
        at java.lang.J9VMInternals.prepareClassImpl(Native Method)
        at java.lang.J9VMInternals.prepare(J9VMInternals.java:303)
        at java.lang.Class.getMethodHelper(Class.java:1247)
        at java.lang.Class.getMethod(Class.java:1191)
        at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:556
)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:538)
Caused by: java.lang.ClassNotFoundException: org.apache.sshd.common.KeyPairProvi
der
        at java.net.URLClassLoader.findClass(URLClassLoader.java:610)
        at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:944)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:889)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:872)
        ... 6 more

The code that starts my java based SSHD is here:

import org.apache.sshd.SshServer;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WinSSHServer {
	public WinSSHServer(Properties props) throws IOException {
		final SshServer sshd = SshServer.setUpDefaultServer();

		sshd.getProperties().put(SshServer.IDLE_TIMEOUT, String.valueOf(sessionTimeoutMSec));
		sshd.setPort(22);
		sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(props.getProperty("hostkey")));
		sshd.setCommandFactory(new WinCmdExeCommandFactory());

		final PuTTYPublicKeyAuthenticator pka = new PuTTYPublicKeyAuthenticator();
		addPublicKeysFromProps(pka, props);
		sshd.setPublickeyAuthenticator(pka);

		sshd.start();
	}

答案1

得分: 0

可能在版本0.14.0和2.5.1之间存在巨大差异。那个类在2.5.1中可能实际上并不存在。因此,

  1. 首先尝试使用新版本编译项目(而不是更改lib中的jar包)。
  2. 根据新版本调整代码以符合要求。
英文:

Probably there is a huge difference between version 0.14.0 and 2.5.1 That class may not really exist in 2.5.1 Therefore

  1. try to compile your project with the new version first (instead of changing the jars in the lib)
  2. change your code accordingly to comply with the new version

答案2

得分: 0

我在一个Maven仓库索引站点中搜索,并找到了一个包含相同类的JAR文件。然而,路径发生了变化,您可能需要在您的端上进行配置。

我使用一个压缩工具(7zip)进行了这个操作,通过搜索包来找到所问类的类名及其完全限定的类路径。当然,还有其他的方法可以实现同样的目的。

https://mvnrepository.com/artifact/org.apache.sshd/sshd-common/2.5.1

原帖中异常堆栈中给出的路径是 org.apache.sshd.common.KeyPairProvider,但在这个包中,它似乎是 org.apache.sshd.common.keyprovider.KeyPairProvider(注意增加了 keyprovider)。

故障排除步骤:

  1. 确认您的JAR文件中是否存在该类。
  2. 如果 KeyPairProvider 的完全限定类名确实如上所述发生了变化,请更新对新的完全限定类名的引用。
英文:

I searched in a maven repository index site and found a JAR that contains the same class. However, there is a change in the path that you likely have to configure on your end.

I did this using a zip utility (7zip) to search through the packages to find the class name in question and its fully-qualified class path. There are other ways to do this as well.

https://mvnrepository.com/artifact/org.apache.sshd/sshd-common/2.5.1

The path given in the exception stack by original poster is org.apache.sshd.common.KeyPairProvider however in this package it appears to be org.apache.sshd.common.keyprovider.KeyPairProvider (note the keyprovider that was added).

Steps to troubleshoot:

  1. Confirm you have the class present in one of your jars
  2. If the fully qualified class name for KeyPairProvider did change as mentioned above then update references to the new fully qualified class name

huangapple
  • 本文由 发表于 2020年9月15日 21:25:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63902860.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定