Java Web Start - 运行时出现 ClassNotFoundException [英] Java Web Start - ClassNotFoundException when running

查看:34
本文介绍了Java Web Start - 运行时出现 ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am now trying to deploy a Java application with Java Web Start. The application works fine when running standalone. I exported the project as a runnable .jar file, and then wrote the corresponding jnlp file.

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

However, when running from the jnlp file, the application returns the following error when starting up:

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

我使用 Eclipse Helios 导出了 .jar 文件,并带有选项将所需的库打包到生成的 JAR 中".

I exported the .jar file using Eclipse Helios with the option "Package required libraries into generated JAR".

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

Here's what my jnlp file looks like (I substituted some information):

<?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 来托管文件,但我怀疑这会有什么不同.

In addition, I am using WebLogic 10 to host the files, but I doubt that will make any difference.

有人可以帮我吗?

感谢您的任何意见!

推荐答案

来自 WebStart 开发人员指南:

必须从 JNLP 文件的资源部分中指定的 JAR 文件中检索所有应用程序资源,或者使用对 Web 服务器的 HTTP 请求显式检索.建议将资源存储在 JAR 文件中,因为它们会被 Java Web Start 缓存在本地机器上.

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 中"会导致您的情况出现问题.

So the class loader mechanism is different for WebStart applications. I assume it's the packaging option "Package required libraries into generated JAR" that causes problems in your case.

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

Is the class someClasscontained in a jar that is contained within your signed.jar file? If so, this would back this theory - try generating separate jar files (don't forget to sign them all!) and reference each of them in the <resources> section as a separate <jar> entry.

这篇关于Java Web Start - 运行时出现 ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆