【问题标题】:Java applet calling WCF Service fails with noclassdef exception at runtime调用 WCF 服务的 Java 小程序在运行时失败并出现 noclassdef 异常
【发布时间】:2013-05-12 18:48:05
【问题描述】:

我有一个 java 小程序,它使用 WCF 服务的代理服务来显示数据。小程序在 Eclipse 中编译和运行完美,但是当我构建和导出 Jar 文件然后在 html 页面中运行它时失败并显示

java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException.

我在构建路径中包含了 jaxrpc.jar,并且我的 jar 文件包含所有必要的类。

堆栈跟踪似乎在抱怨我从小程序类中实例化代理服务的那一行。有谁知道从 java 小程序调用 WCF 服务是否有问题?

堆栈跟踪:

java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.instantiateApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException
at ListProducts.ListProducts.<init>(ListProducts.java:25)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.xml.rpc.ServiceException
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 27 more

这件事困扰了我一整天。

【问题讨论】:

  • “我在构建路径中包含了 jaxrpc.jar,并且我的 jar 文件包含了所有必要的类。” 这是什么意思?这是否意味着您已将 WFC 类包含在 HTML 中引用的“胖 jar”中?发布用于启动它的 HTML,以及 archive 属性中每个 Jar 的 jar -tvf the.jar

标签: java wcf service proxy applet


【解决方案1】:

我认为您的问题是加载 rpc jar,而不是调用 wcf。

这篇文章可能会有所帮助: http://www.coderanch.com/t/259357/Applets/java/Applet-Axis-Client-Errors

建议对您的 jar 进行签名,验证您可以通过浏览器访问所有 jar,确保您拥有所有dependent.jar。

如果这一切都无济于事 - 我会尝试将其解决为“ 来自 splet 的 NoClassDefFoundError”问题。

【讨论】:

  • 我也想知道这个。我已经下载了 rpc jar 文件并将其解压缩到我的 eclipse 插件中,但我想知道浏览器是否找不到它。我需要把它解压到我的 JDK 文件夹吗?
  • Jar 文件已签名,可从浏览器访问。 “依赖”罐子是什么意思?我有一个 jar,其中包含小程序使用的所有类。如果 rpc jar 是依赖的,那么我需要将它包含在我的主 jar 文件中吗?
  • 依赖 - 我的意思是,这个 jar 可能使用了一些额外的 jar,比如 commons-logging.jar、common-language.jar,...(来自同一个链接的帖子,我不确定这个)
  • 我明白你的意思。我今天花了将 jars 添加到 html 中的存档参数并注意到我得到的新错误。我现在已经碰到了一堵砖墙,因为它抱怨 'code'java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "createClassLoader")
【解决方案2】:

好的。我通过做几件事来完成这项工作:

首先我必须签署几个我正在使用的 jar 文件:

jaxrpc.jar

axis.jar

commons-discovery-0.2.jar

但不是:

javax.wsdl_1.6.2.v201012040545.jar

org.apache.commons.logging_1.0.4.v201101211617.jar

其次 - 所有这些文件都必须与 html 页面存在于同一目录中,因为我没有在代码库属性中为 applet 标记指定目录。

第三,在我的主小程序 (ListProducts.class) 中,我必须在首先调用代理服务的代码周围使用 AccessController.doPrivileged(): 编辑:这一步可能没有必要,因为当我删除 doPrivileged 块时它现在似乎可以工作。

AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {

    try {

        //instantiate proxy service and make rpc's
        //do other stuff with results...


    } catch (RemoteException e) {
        // catch error
    }           


        return null;
        }
    });

这种组合使 java 小程序完成了它应该做的事情。发现缺少哪些 jar 文件然后签署适当的文件是一个痛苦的缓慢过程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 2018-02-02
    相关资源
    最近更新 更多