Java Web Start - 运行时出现 ClassNotFoundException

标签 java deployment jnlp java-web-start classnotfoundexception

我现在正尝试使用 Java Web Start 部署 Java 应用程序。该应用程序在独立运行时运行良好。我把项目导出为可运行的.jar文件,然后写了对应的jnlp文件。

但是,从jnlp文件运行时,应用程序在启动时返回如下错误:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: someClass
........
Caused by: java.lang.ClassNotFoundException: someClass
.........

我使用 Eclipse Helios 导出了 .jar 文件,并选择了“将所需的库打包到生成的 JAR 中”。

这是我的 jnlp 文件的样子(我替换了一些信息):

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" 
    codebase="................" 
    href="thisJNLP.jnlp">
    <information>
        <title>Whatever</title>
        <vendor>Whatever</vendor>
    </information>
    <security>
        <all-permissions/>
    </security>

    <resources>
        <!-- Application Resources -->
        <j2se version="1.6+"
              href="http://java.sun.com/products/autodl/j2se"/>
        <jar href="signed.jar" main="true" />

    </resources>
    <application-desc
         name="Whatever"
         main-class="thisProject.main"
         width="300"
         height="300">
     </application-desc>
     <update check="background"/>
</jnlp>

此外,我正在使用 WebLogic 10 来托管文件,但我怀疑这会有什么不同。

有人能帮帮我吗?

感谢您的任何意见!

最佳答案

来自WebStart Developer's Guide :

All application resources must be retrieved from the JAR files specified in the resources section of the JNLP file, or retrieved explicitly using an HTTP request to the Web server. Storing resources in JAR files is recommended, since they will be cached on the local machine by Java Web Start.

因此类加载器机制对于WebStart 应用程序是不同的。我认为是打包选项“将所需的库打包到生成的 JAR 中”导致您的情况出现问题。

是类 someClass包含在您的 signed.jar 中的 jar 中文件?如果是这样,这将支持这个理论——尝试生成单独的 jar 文件(不要忘记对它们全部签名!)并在 <resources> 中引用它们中的每一个。作为单独的部分 <jar>入口。

关于Java Web Start - 运行时出现 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6612556/

相关文章:

java - 使用工厂返回多个 JButton 数组...?

java - 来自 4x4 变换矩阵 (libgdx) 的意外旋转角度

php - 在生产中升级到 Drupal

Java如何在另一个类中使用 Activity 方法

java - PowerMockito。模拟静态方法。为什么 PowerMockito#stub 不起作用?

Java Web 启动问题

Java webstart权限问题

即使客户端是 64 位,javaws 也始终加载 32 位库

c++ - 编译 C++ 应用程序,以便它们也可以在其他计算机上工作

linux - 使用 Puppet 管理 shell 命令