我有一个OpenFire服务器,我正在尝试构建一个Smack客户端来连接它。最初,我只是尝试使用Smack API和下面的代码(来自答案here):
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Presence;
public class Main {
public static void main(String[] args)
{
ConnectionConfiguration config = new ConnectionConfiguration(
"talk.google.com", 5222, "google.com");
XMPPConnection connection = new XMPPConnection(config);
Presence presence;
String status;
try {
connection.connect();
connection.login("mail_id@gmail.com", "password");
status = "DND";
presence = new Presence(Presence.Type.available, status, 24,
Presence.Mode.available);
while (true) {
status = set(status);
presence.setStatus(status);
connection.sendPacket(presence);
Thread.sleep(1000);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
connection.disconnect();
}
}
private static String set(String input) {
return input.substring(1) + input.charAt(0);
}
}
但是,我一直收到以下错误
线程“main”中的异常java.lang.NoClassDefFoundError: org / kxml2 / io / KXmlParser at org.jivesoftware.smack.XMPPConnection。(XMPPConnection.java:110) 在 org.jivesoftware.smack.ConnectionConfiguration。(ConnectionConfiguration.java:57) 在Main.main(Main.java:8)引起: java.lang.ClassNotFoundException:org.kxml2.io.KXmlParser at java.net.URLClassLoader.findClass(URLClassLoader.java:381)at java.lang.ClassLoader.loadClass(ClassLoader.java:424)at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:335)at at java.lang.ClassLoader.loadClass(ClassLoader.java:357)... 3更多
任何帮助将不胜感激