Java XMPP clint with smack 4.1 NoClassDefFoundError:

时间:2015-05-14 18:24:06

标签: eclipse maven gradle build.gradle smack

我正在尝试使用smack 4.1.1编写XMPP Clint。我已将smack jar文件添加到构建路径中。我正在使用eclipse IDE编写代码。

但是,当我尝试运行应用程序时,我得到NoClassDefFoundErrors。我修复了一些错误,将xpp3,jxmpp和minidns jar文件添加到构建路径中。然而,我收到以下错误。

Exception in thread "main" java.lang.NoClassDefFoundError: org/jxmpp/util/cache/ExpirationCache
at org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver.<clinit>(MiniDnsResolver.java:46)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:213)
at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:116)
at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
at JabberSmackAPI.login(JabberSmackAPI.java:29)
at JabberSmackAPI.main(JabberSmackAPI.java:76)
Caused by: java.lang.ClassNotFoundException: org.jxmpp.util.cache.ExpirationCache
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 12 more

如何解决此问题?

在互联网上,建议使用gradle或maven来构建相同的内容。如果是这样,你能帮我怎么用?我以前从未使用过它们。

1 个答案:

答案 0 :(得分:2)

如下面的堆栈跟踪

Caused by: java.lang.ClassNotFoundException: org.jxmpp.util.cache.ExpirationCache
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

看起来您在类路径中缺少jxmpp-util-cache-0.5.0-alpha2.jar。 Download并将此jar添加到应用程序的lib/目录中。

  

在互联网上,建议使用gradle或maven来构建   相同。如果是这样,你能帮助我如何使用它吗?

在eclipse中创建一个meven项目。如果你是meven项目的新手,请参考

  

How to create a Java project with Maven

并将下面的依赖项添加到您的meven构建项目的pom.xml

<dependency>
   <groupId>org.igniterealtime.smack</groupId>
      <artifactId>smack-java7</artifactId>
      <version>4.1.0</version>
 </dependency>
<dependency>
        <groupId>org.igniterealtime.smack</groupId>
        <artifactId>smack-tcp</artifactId>
        <version>4.1.0</version>
</dependency>
<dependency>
        <groupId>org.igniterealtime.smack</groupId>
        <artifactId>smack-im</artifactId>
        <version>4.1.0</version>
</dependency>
<dependency>
        <groupId>org.igniterealtime.smack</groupId>
        <artifactId>smack-extensions</artifactId>
        <version>4.1.0</version>
</dependency>

有关详细信息,请参阅此link

希望这会对你有所帮助!!!!

感谢!!!