Eclipse构建> Sign Jar> Jnlp部署过程

时间:2012-11-30 20:18:26

标签: java deployment jnlp java-web-start

目前我收到有关如何找不到我的包含内容的错误,特别是

java.lang.ClassNotFoundException: org.jivesoftware.smack.provider.ProviderManager

我已经确认该文件作为可执行jar运行,所以我真的不知道为什么它会像这样出错,有人能给我一些见解吗?

以下是我目前正在做的事情,如果任何步骤错误,请纠正我。

  1. 我接受我的(确认工作)程序,运行它进行仔细检查。
  2. 我右键单击项目>出口> 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>
    
  3. 从那里我右键点击&gt;以&gt;运行蚂蚁建立文件签署我的罐子。

  4. 然后我将它移动到我的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>
    
  5. 启动应用程序时的完整堆栈跟踪:

    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)
    

    这就是我的罐子里面 This is what the inside of my jar looks like

1 个答案:

答案 0 :(得分:2)

正如@AkselWillgert所提到的,标准的Java类加载器不会从其他Jars中的Jars加载类。有必要做一个:

  1. 在JNLP的resources部分添加对每个Jar的引用。或者事实上,我们可以更进一步,将常用的API放入可供许多应用程序使用的扩展中。 commons-logging.jnlpjive.jnlp
  2. 从所有Jars中提取类并将它们添加到一个Jar中。这通常违反API的用户协议,破坏可能在服务提供商界面中表达的数字签名和有用的清单信息。
  3. 安装一个可以在Jars中读取Jar的类加载器。这需要一个值得信赖的应用程序。
  4. 由于各种原因,第一个是最好的选择。


      

    ..我将如何签署所有这些罐子?

    咨询signjar task的文档会提示(复制/粘贴):

    <signjar
        alias="testonly" keystore="testkeystore"
        storepass="apacheant"
        lazy="true"
        >
      <path>
        <fileset dir="dist" includes="**/*.jar" />
      </path>
    </signjar>
    

    警告

    某些罐子可能已经过数字签名。如果是这样,最好保留原始签名。如何做到这一点,更多的是关于构建工具的问题。