目前我收到有关如何找不到我的包含内容的错误,特别是
java.lang.ClassNotFoundException: org.jivesoftware.smack.provider.ProviderManager
我已经确认该文件作为可执行jar运行,所以我真的不知道为什么它会像这样出错,有人能给我一些见解吗?
以下是我目前正在做的事情,如果任何步骤错误,请纠正我。
我右键单击项目>出口> Runnable jar文件并选择选项>将所需的库打包到生成的jar文件中,并将Ant Build脚本导出到文件myProg.xml
当myprog.xml出现时,它看起来像这样:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for Project myProg with Jar-in-Jar Loader">
<!--this file was created by Eclipse Runnable JAR Export Wizard-->
<!--ANT 1.7 is required -->
<target name="create_run_jar">
<jar destfile="C:/Users/Dbell/Documents/EclipseProjects/myProg/myProg.jar">
<manifest>
<attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
<attribute name="Rsrc-Main-Class" value="com.myCom.noc.xmpptroubleshooter.Main"/>
<attribute name="Class-Path" value="."/>
<attribute name="Rsrc-Class-Path" value="./ httpasyncclient-4.0-beta2.jar httpcore-4.2.1.jar httpcore-nio-4.2.1.jar httpclient-4.2.1.jar commons-logging-1.1.1.jar commons-codec-1.6.jar log4j-1.2.12.jar logkit-1.0.1.jar avalon-framework-4.1.3.jar servlet-api-2.3.jar commons-net-3.1.jar xpp3_min-1.1.4c.jar NocLib-1.1.jar smack32-3.2.0.jar httpclient-3.1.jar"/>
</manifest>
<zipfileset src="jar-in-jar-loader.zip"/>
<fileset dir="C:/Users/Dbell/Documents/EclipseProjects/myProg/bin"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\org.apache.httpcomponents\httpasyncclient\jars" includes="httpasyncclient-4.0-beta2.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\org.apache.httpcomponents\httpcore\jars" includes="httpcore-4.2.1.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\org.apache.httpcomponents\httpcore-nio\jars" includes="httpcore-nio-4.2.1.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\org.apache.httpcomponents\httpclient\jars" includes="httpclient-4.2.1.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\commons-logging\commons-logging\jars" includes="commons-logging-1.1.1.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\commons-codec\commons-codec\jars" includes="commons-codec-1.6.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\log4j\log4j\jars" includes="log4j-1.2.12.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\logkit\logkit\jars" includes="logkit-1.0.1.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\avalon-framework\avalon-framework\jars" includes="avalon-framework-4.1.3.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\javax.servlet\servlet-api\jars" includes="servlet-api-2.3.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\commons-net\commons-net\jars" includes="commons-net-3.1.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\xpp3\xpp3_min\jars" includes="xpp3_min-1.1.4c.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\com.MyCom\NocLib\jars" includes="NocLib-1.1.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\com.MyCom\smack32\jars" includes="smack32-3.2.0.jar"/>
<zipfileset dir="C:\Users\Dbell\.ivy2\cache\com.apache\httpclient\jars" includes="httpclient-3.1.jar"/>
</jar>
<signjar jar="myProg.jar" alias="myAlias" keystore="path/to/myKs.ks" storepass="MyPass"/>
</target>
</project>
从那里我右键点击&gt;以&gt;运行蚂蚁建立文件签署我的罐子。
然后我将它移动到我的web服务器,其中存在launch.jnlp文件。看起来像这样:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="http://myServer:8080/myProg/" href="http://myServer:8080/myProg/launch.jnlp" spec="6.0+">
<information>
<title>myProg</title>
<vendor>myName</vendor>
<homepage href="http://myServer:8080/myProg/"/>
<description>myProg</description>
<description kind="short">myProg</description>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" />
<jar href="myProg.jar" main="true"/>
</resources>
<application-desc main-class="com.myCom.noc.pathToMain.Main">
</application-desc>
</jnlp>
启动应用程序时的完整堆栈跟踪:
java.lang.ClassNotFoundException: org.jivesoftware.smack.provider.ProviderManager
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.myCom.noc.xmpptroubleshooter.Main.main(Main.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
这就是我的罐子里面
答案 0 :(得分:2)
正如@AkselWillgert所提到的,标准的Java类加载器不会从其他Jars中的Jars加载类。有必要做一个:
resources
部分添加对每个Jar的引用。或者事实上,我们可以更进一步,将常用的API放入可供许多应用程序使用的扩展中。 commons-logging.jnlp
或jive.jnlp
。由于各种原因,第一个是最好的选择。
..我将如何签署所有这些罐子?
咨询signjar
task的文档会提示(复制/粘贴):
<signjar
alias="testonly" keystore="testkeystore"
storepass="apacheant"
lazy="true"
>
<path>
<fileset dir="dist" includes="**/*.jar" />
</path>
</signjar>
某些罐子可能已经过数字签名。如果是这样,最好保留原始签名。如何做到这一点,更多的是关于构建工具的问题。