0

我在 NetBeans 中编写了一个简单的 Java 小程序,但在嵌入它时遇到了真正的麻烦。我将我的类文件复制到与我的 html 页面相同的目录中。我也把我的 .jar 放在那里。在我做的html页面上

<applet code="ServerStatus.class" width="200" height="200">
Your browser does not support the <code>applet</code> tag.
</applet> 

但是小程序永远不会加载。长错误的第一位是:

load: class ServerStatusChecker.jar not found.
java.lang.ClassNotFoundException: ServerStatusChecker.jar

我必须做什么才能嵌入这个小程序?我的 MyApplet.java 文件的顶部是

package org.me.serverstatuschecker;

import java.applet.*;
import java.awt.*; 
import java.awt.event.*;
import java.io.*;
import java.net.*;

public class MyApplet extends Applet implements ActionListener  {

我的 ServerStatusChecker.jar 与我试图将其包含在其中的 html 文件位于同一位置。在 jar 中,我有文件夹 org/me/serverstatuschecker/MyApplet.class。

编辑:

完整的错误信息如下:

 Java Plug-in 1.6.0_31
 Using JRE version 1.6.0_31-b05 Java HotSpot(TM) Client VM

 ----------------------------------------------------


    java.lang.UnsupportedClassVersionError: org/me/serverstatuschecker/ServerStatusChecker : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.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.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)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.UnsupportedClassVersionError: org/me/serverstatuschecker/ServerStatusChecker : Unsupported major.minor version 51.0
    java.lang.UnsupportedClassVersionError: org/me/serverstatuschecker/ServerStatusChecker : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.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.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)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.UnsupportedClassVersionError: org/me/serverstatuschecker/ServerStatusChecker : Unsupported major.minor version 51.0
    java.lang.UnsupportedClassVersionError: org/me/serverstatuschecker/ServerStatusChecker : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.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.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)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.UnsupportedClassVersionError:      org/me/serverstatuschecker/ServerStatusChecker : Unsupported major.minor version 51.0
    java.lang.UnsupportedClassVersionError: org/me/serverstatuschecker/ServerStatusChecker :   Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.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.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)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.UnsupportedClassVersionError:          org/me/serverstatuschecker/ServerStatusChecker : Unsupported major.minor version 51.0
4

2 回答 2

3

Directory Structure

  • theappletdir/
    • applet.html
    • ServerStatusChecker.jar

Content of applet.html

Then use the script supplied by Oracle to deploy applets and JWS apps. It is called deployJava.js and linked from the applet info. page. It will:

  • Check the minimum stated JRE version is available for use by applets.
    • If not, help the user to upgrade it.
  • Embed & run the applet.

<html>
<head>
<!-- ... -->
<script src="http://www.java.com/js/deployJava.js"></script>
</head>
<body>
<!-- ... -->
<script>
    var attributes = {codebase:'.',
                      code:'org.me.serverstatuschecker.MyApplet',
                      archive:'ServerStatusChecker.jar',
                      width:200, height:200};
    var parameters = {};
    var version = '1.6';  // or whatever version the code was compiled for 
    deployJava.runApplet(attributes, parameters, version);
</script>
</body>
</html>

New Error

UnsupportedClassVersionError: org/me/serverstatuschecker/MyApplet : 
    Unsupported major.minor version 51.0

When I refer to the version number list it indicates the code is being compiled compatible for a 1.7 JRE, whereas the version attribute above indicates the code should be able to be loaded in any 1.6+ JRE. The best way to fix this is to use the source, target bootclasspath options when compiling the code. Specify the first 2 as 1.6 and the last as a path to a 1.6 version rt.jar.

于 2012-04-24T15:32:49.607 回答
0

您是否尝试过 HtmlConverter 工具?

http://java.sun.com/products/plugin/1.3/docs/htmlconv.html

它创建一个 HTML 代码,尝试使用 Java 插件正确加载您的小程序。

于 2012-04-24T15:19:06.197 回答