问题
I have an applet jar file cia.jar
and the class in it main.class
and I have my class in the package com.gmail.connorbphtml.WebApp
. I am trying to embed my applet into a webpage. When I am trying to do this I get a class not found error.
The applet works fine in Eclipse but then when I try to embed it it does not work.
Here is my HTML using embed:
<embed code="main.class"
archive="cia.jar"
width="200" height="200"
type="application/x-java-applet;version=1.6.0"
pluginspage="http://java.sun.com/javase/downloads"/>
I have been having this problem for months which made me give up applets because I can't get this working.
Does anyone know what went wrong?
The results from jar -tvf cia.jar
are:
39 Sun Sep 16 12:34:50 EDT 2012 META-INF/MANIFEST.MF
0 Sat Sep 15 18:02:30 EDT 2012 com/
0 Sat Sep 15 18:02:30 EDT 2012 com/gmail/
0 Sat Sep 15 18:02:30 EDT 2012 com/gmail/connorbphtml/
0 Sat Sep 15 18:02:30 EDT 2012 com/gmail/connorbphtml/WebApp/
136 Sat Sep 15 18:02:16 EDT 2012 com/gmail/connorbphtml/WebApp/package-info.class
692 Sat Sep 15 23:26:08 EDT 2012 com/gmail/connorbphtml/WebApp/main.class
226 Sat Sep 15 18:01:20 EDT 2012 .classpath
366 Sat Sep 15 18:01:20 EDT 2012 .project
The error in the console:
Java Plug-in 1.6.0_33
Using JRE version 1.6.0_33-b03-424-11M3720 Java HotSpot(TM) 64-Bit Server VM
User home directory = /Users/Connor
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
Java Plug-in 1.6.0_33
Using JRE version 1.6.0_33-b03-424-11M3720 Java HotSpot(TM) 64-Bit Server VM
User home directory = /Users/Connorload: class Sun_Microsystems_Java_Security_Update_6.class not found.
java.lang.ClassNotFoundException: Sun_Microsystems_Java_Security_Update_6.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
load: class com/gmail/connorbphtml/WebApp/main.class not found.
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
load: class com/gmail/connorbphtml/WebApp/main.class not found.
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:690)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3045)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
at java.lang.Thread.run(Thread.java:680)
Exception: java.lang.ClassNotFoundException: Sun_Microsystems_Java_Security_Update_6.class
java.lang.ClassNotFoundException: com.gmail.connorbphtml.WebApp.main.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:690)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3045)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
at java.lang.Thread.run(Thread.java:680)
Exception: java.lang.ClassNotFoundException: com.gmail.connorbphtml.WebApp.main.class
java.lang.ClassNotFoundException: com.gmail.connorbphtml.WebApp.main.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:690)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3045)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
at java.lang.Thread.run(Thread.java:680)
Exception: java.lang.ClassNotFoundException: com.gmail.connorbphtml.WebApp.main.class
回答1:
Use deployJava.js
to write the element for the applet.
E.G. adapted from the page:
<script src="http://www.java.com/js/deployJava.js"></script>
<script>
var attributes = {codebase:'.',
code:'com.gmail.connorbphtml.WebApp.main',
archive:'cia.jar',
width:200, height:200};
var version = '1.6';
deployJava.runApplet(attributes, parameters, version);
</script>
The script will write the appropriate element in the correct form for the browser/OS on which it is running.
回答2:
Code should not contain .class
extension. Try this.
<applet code="com.gmail.connorbphtml.WebApp.main" archive="cia.jar"
width="200" height="200"></applet>
Also you did not include the package
name in the code
attribute.
来源:https://stackoverflow.com/questions/12444581/applet-embed-tag-is-returning-classnotfoundexception