我正在尝试使用JNLP
部署我的applet。我尝试过使用Eclipse Run Jetty Run
插件,它运行正常。但现在部署在真正的Web服务器上,我真的陷入困境。
我的jnlp文件草图是这样的(我hava编辑了一些名字)。
<?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脚本
<manifest>
<attribute name="Class-Path" value="."/>
<attribute name="Rsrc-Class-Path" value="./"/>
</manifest>
所有罐子都已签名,这是我从控制台日志中得到的:
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);
它是applet中的第一个类,应该从外部库加载。
所有jars,htmls和jnlps都位于http://mydomain.com/play/
,我访问applet http://mydomain.com/play/applet.html
来自Incompatible magic value 1008813135
我了解到1130458734
表示Cann
,如果访问Cannot find block '__global__'
,我真的会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>
答案 0 :(得分:0)
我假设applet的类路径中的URL,并且由于Web服务器返回消息而不是某些HTTP File Not Found状态代码,因此它认为它有一个可以使用的类。
这是一个很好的猜测!对于任何未找到的资源,网络服务器都没有在标头中返回404错误,它只返回了一些文本。因此,Java将其解释为好像找到了资源,并且尝试将其作为Java类加载失败。