samuraiseoul
samuraiseoul

Reputation: 2967

Java Applet, works in eclipse, not chrome

I have a very simple java applet, that Im using source code from the docs.oracle(http://docs.oracle.com/javase/tutorial/deployment/applet/getStarted.html) site that should work, and it works in eclipse just fine, it's getting it onto the page that's the problem. The file is on a localhost server at localhost/applet/applet.html and I have the file JavaQuiz.jar in the same directory. My html file is as follows.

<hmtl>
<applet codebase="localhost/applet/"
    code = 'JavaQuiz.jar' 
    archive = 'JavaQuiz.jar'
    width = 300
    height = 300 />
</html>

Is there something Im missing? Or need to change? I look forward to any help that could be given, and please try to explain it more than telling me the answer so I can learn. :D

This is what is in the java colsole Java Plug-in 10.5.1.255 Using JRE version 1.7.0_05-b05 Java HotSpot(TM) Client VM

User home directory = C:\Users\Jihoon

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

plugin2manager.parentwindowDispose

The Chrome developer help thing doesn't show any problems. And when I click details on the applet it just says classnotfounfexception: JavaQuiz

Upvotes: 1

Views: 1387

Answers (6)

Andrew Thompson
Andrew Thompson

Reputation: 168845

http://localhost/applet/JavaQuiz.jar will not work at time of deployment.

<html>
<applet 
    codebase="."
    archive="JavaQuiz.jar" 
    code="JavaQuiz"
    width = 300
    height = 300 >
</applet>
</html>

Since the code base points to the 'current directory' this will work for the applet while on localhost as well as deployed live.

Points, some of which have already been mentioned:

  1. The code attribute should be the fully qualified class name of the applet class, without .class on the end.
  2. The applet element cannot be 'self closed' - always use </applet> to close the element.
  3. If omitted the code base defaults to the directory the HTML is in, so putting codebase="." is redundant. It should also work without it.

Upvotes: 1

Kenny Cason
Kenny Cason

Reputation: 12328

<html>
<applet 
    archive="http://localhost/applet/JavaQuiz.jar" 
    code="JavaQuiz.class"
    width = 300
    height = 300 />
</html>

I think the biggest problem is not having the http:// I'm not entirely sure about the other parameters. Play around with that.

So in your case change codebase="localhost/applet/" to codebase="http://localhost/applet/"

Upvotes: 2

paulgavrikov
paulgavrikov

Reputation: 1891

Also you should have an eye on localhost... this means that the j.jar is located in a folder called localhost in the same directory that the html is in. Is that true? Or do you mean http://localhost:80/applet/ or /applet/

Upvotes: 2

LuGo
LuGo

Reputation: 5045

The mandatory "code" attribute (which is missing in your example) should point to the class which you intend to run (the one extending JApplet). Something like:

<html>
<applet codebase="localhost/applet/" code="yourpackage.YourApplet.class"
    code = 'JavaQuiz.jar' 
    archive = 'JavaQuiz.jar'
    width = 300
    height = 300 />
</html>

Upvotes: 1

paulgavrikov
paulgavrikov

Reputation: 1891

<hmtl> should be <html>

Upvotes: 1

Alohci
Alohci

Reputation: 83125

The code attribute should point to a fully qualified class name, not to a jar.

Upvotes: 2

Related Questions