2

我正在尝试使用JNLP. 我试过使用 EclipseRun Jetty Run插件,它工作正常。但是现在在真正的 Web 服务器上进行部署时,我真的被卡住了。

我的 jnlp 文件草图是这样的(我已经编辑了一些名称)。

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" href="MyApplet.jnlp">
    <information>
        <title>MyApplet</title>
        <vendor>Me</vendor>
        <offline-allowed/>
    </information>
    <security>
        <j2ee-application-client-permissions/>
    </security>
    <resources>
        <!-- Application Resources -->
        <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
        <jar href="applet.jar" part="true" main="true"/>
        <jar href="log4j-1.2.16.jar" part="true"/>
        <jar href="slf4j-api-1.6.1.jar" part="true"/>
        <jar href="slf4j-log4j12-1.6.1.jar" part="true"/>
    </resources>
    <!--  Generate values dynamically -->
    <applet-desc main-class="org.project.applet.AppletMain" name="MyApplet" width="1600" height="860"/>
</jnlp>

我将库与applet.jar.

关于清单文件applet.jar我不确定,我尝试了很多选项,比如指定库,或者只是.目前它就像在 Ant 脚本中一样

Java 小程序 jnlp + 库

<manifest>
    <attribute name="Class-Path" value="."/>
    <attribute name="Rsrc-Class-Path" value="./"/>
</manifest>

所有 jar 都已签名,这是我从控制台日志中得到的:

basic: Applet loaded.
basic: Applet resized and added to parent container
basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 134206 us, pluginInit dt 7621660339 us, TotalTime: 7621794545 us
network: Cache entry not found [url: http://mydomain.com/play/, version: null]
network: Cache entry not found [url: http://mydomain.com/play/org/apache/log4j/Logger.class, version: null]
network: Connecting http://mydomain.com/play/org/apache/log4j/Logger.class with proxy=DIRECT
network: Connecting http://mydomain.com/play/org/apache/log4j/Logger.class with cookie "PHPSESSID=fe5gv8p4hp013r6i9p5aqjska5"
network: Connecting http://mydomain.com:80/ with proxy=DIRECT
network: Connecting http://mydomain.com/play/org/apache/log4j/Logger.class with cookie "PHPSESSID=fe5gv8p4hp013r6i9p5aqjska5"
basic: JNLP2ClassLoader.findClass: org.apache.log4j.Logger: try again ..
network: Cache entry not found [url: http://mydomain.com/play/org/apache/log4j/Logger.class, version: null]
network: Connecting http://mydomain.com/play/org/apache/log4j/Logger.class with proxy=DIRECT
network: Connecting http://mydomain.com/play/org/apache/log4j/Logger.class with cookie "PHPSESSID=fe5gv8p4hp013r6i9p5aqjska5"
basic: Dialog type is not candidate for embedding
basic: JNLP2ClassLoader.getPermissions() ..
network: Cache entry not found [url: http://mydomain.com/play/org/apache/log4j/Logger.class, version: null]
security: JAVAWS AppPolicy Permission requested for: http://mydomain.com/play/org/apache/log4j/Logger.class
basic: JNLP2ClassLoader.getPermissions() X
java.lang.ClassFormatError: Incompatible magic value 1130458734 in class file org/apache/log4j/Logger
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.defineClassHelper(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.access$100(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
    at sun.plugin2.applet.JNLP2ClassLoader.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)
    at org.project.applet.AppletMain.init(AppletMain.java:32)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
security: Reset deny session certificate store

第 32 行是

Logger.getRootLogger().setLevel(Level.OFF);

它是小程序中的第一类,应该从外部库加载。

所有 jars、htmls 和 jnlps 都在里面http://mydomain.com/play/,我可以访问 applethttp://mydomain.com/play/applet.html

Incompatible magic value 1008813135 我了解到这1130458734意味着Cann我真的得到了Cannot find block '__global__'if access http://mydomain.com/play/org/apache/log4j/Logger.class

但我不明白为什么在 jar 中搜索类会失败,以及为什么它会尝试访问http://mydomain.com/play/org/apache/log4j/Logger.class服务器上不存在的类。

编辑:

我的 html 文件来自 Oracle 教程:

<html>
<head>
    <title>MyApplet</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <script src="http://www.java.com/js/deployJava.js"></script>
</head>
<body>
    <script>
        var attributes = {code:'org.project.applet.AppletMain', width:1600, height:860} ;
        var parameters = {jnlp_href: 'MyApplet.jnlp'} ;
        deployJava.runApplet(attributes, parameters, '1.6');
    </script>
</body>
</html>
4

1 回答 1

0

彼得劳里:

我假设小程序的类路径中的 URL 并且由于 Web 服务器返回一条消息而不是一些 HTTP File Not Found 状态代码,它认为它有一个可以使用的类。

这是一个很好的猜测!网络服务器没有在任何未找到的资源的标头中返回 404 错误,它只返回一些文本。因此 Java 将其解释为好像找到了资源并且尝试将其作为 Java 类加载失败。

于 2013-02-04T05:06:44.040 回答