gpt4 book ai didi

java - 错误 : "Caused by: java.lang.ClassNotFoundException: org.eclipse.paho.client.mqttv3.MqttCallback" when doing java -jar myproyect. jar

转载 作者:行者123 更新时间:2023-12-02 08:54:33 29 4
gpt4 key购买 nike

当我尝试使用 java -jar 运行我的项目时,出现了该错误。我的项目是一个具有 Controller 类的 MQTT 服务器:

public class ControladorMQTT

和回调类:

public class CallbackMQTT implements MqttCallback

似乎没有检测到回调类。

这是完整的错误:

C:\Users\Moreno\Documents\IntelliJ\ControladorMQTT\out\artifacts\ControladorMQTT_jar>java -jar ControladorMQTT.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/paho/client/mqttv3/MqttCallback
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.eclipse.paho.client.mqttv3.MqttCallback
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)
... 7 more

我创建了这样的 MANIFEST.MF:

Manifest-Version: 1.0
Main-Class: MQTT.ControladorMQTT
Class-Path: org.eclipse.paho.client.mqttv3.MqttCallback

编辑

我已经添加了库C:\Users\Moreno\.m2\repository\org\eclipse\paho\org.eclipse.paho.client.mqttv3\1.2.0\org.eclipse.paho.client .mqttv3-1.2.0.jar 到我的应用程序 .jar 目录中,我已将 MANIFEST 修改为如下所示:

Manifest-Version: 1.0
Main-Class: MQTT.ControladorMQTT
Class-Path: org.eclipse.paho.client.mqttv3-1.2.0.jar

但是还是不行。

最佳答案

您需要将外部依赖项(jar 文件)包含到类路径中。像这样的事情:

java -cp C:\path\to\file.jar;C:\path\to\some-lib-jars\*;. -jar ControladorMQTT.jar

参见:

关于java - 错误 : "Caused by: java.lang.ClassNotFoundException: org.eclipse.paho.client.mqttv3.MqttCallback" when doing java -jar myproyect. jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60563649/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com