关于JAVA利用smack连接openfire的jar依赖问题

一、GitHub上的maven依赖

参考https://github.com/igniterealtime/Smack/wiki/Smack-4.2-Readme-and-Upgrade-Guide#using-eclipses-android-development-tools-adt-ant-based-build

直接使用maven依赖

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

二、关于smack-4.3.4的jar包相关依赖

有两种方式

①、引入maven依赖,比4.2.0版本多了一项

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

②、可以在https://www.igniterealtime.org/downloads/download-landing.jsp?file=smack/smack-4.3.4.zip这里下载最新的4.3.4的smack安装包,然后就可以通过和方法①中相关jar包比较差别,引入其他像是jxmpp-core-0.6.4.jar, jxmpp-jid-0.6.4.jar, jxmpp-util-cache-0.6.4.jar, minidns-core-0.3.4.jar, xpp, xpp3_xpath-1.1.4.jar, minidn-cient-0.3.4.jar, minidns-dnssec-0.3.4.jar, minidns-hla-0.3.4.jar, minidns-iterative-resolver-0.3.4.jar以及xpp3-1.1.4c.jar,

注意:最后有个感觉很bug的地方就是maven引入依赖的工程,正常的连接可以建立,可是方法①中直接下载下来的依赖如果运行方法②中测试通过的代码会报一个错误

Exception in thread "main" java.lang.NoClassDefFoundError: org/xbill/DNS/TextParseException
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:193)
	at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:173)
	at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:143)
	at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:128)
	at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:93)
	at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:93)
	at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:64)
	at com.yoplore.smack.SmackTest.main(SmackTest.java:15)
Caused by: java.lang.ClassNotFoundException: org.xbill.DNS.TextParseException
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 10 more

得引入dns-2.0.8.jar才行,maven坐标是

<dependency>
    <groupId>org.xbill</groupId>
    <artifactId>dns</artifactId>
    <version>2.0.8</version>
</dependency>

至此,整个smack连接openfire的基础jar包依赖解决

posted @ 2020-07-06 15:55  MarshWinter  阅读(670)  评论(0编辑  收藏  举报