0

I am trying to run Java applet using Google Chrome browser. Everytime I am getting no class found exception. Here is my code.

HelloWorld.java

package my.first.pack;

import java.applet.Applet;
import java.awt.*;

public class HelloWorld extends Applet {

    /**
     * 
     */
    private static final long serialVersionUID = 2741715258812838900L;

    public void paint(Graphics g) {
        g.drawString("welcome", 150, 150);
    }

}

Hello.html

<applet code="my.first.pack.HelloWorld" width="300" height="300">  
4
  • Have you signed your applet with code signing certificate? Commented Jun 16, 2015 at 10:40
  • Nope. How to do that? Commented Jun 16, 2015 at 11:56
  • Show the directory structure of the server containing the HTML and class file (and their locations relative to each other). @VickyThakor alluded to something that must be fixed eventually, in that the class needs to be in a (signed) Jar these days in order to have any chance of working. As an aside, Chrome is soon to drop all support for the NPAPI that launches (among other things) applets. But .. Commented Jun 18, 2015 at 9:29
  • Why code an applet? If it is due to the teacher specifying it, please refer them to Why CS teachers should stop teaching Java applets. Commented Jun 18, 2015 at 9:29

1 Answer 1

1
  1. Sign your applet and all the .jar dependencies with a certificate.
  2. Populate your manifest with all the tags mentioned below (it's in xml because I use maven, you can write in the way you prefer)
<codebase>http://location.of.your.jar/</codebase>
<permissions>all-permissions</permissions>
<Application-Library-Allowable-Codebase>http://location.of.your.jar/</Application-Library-Allowable-Codebase>
<Manifest-Version>1.0</Manifest-Version>
<Implementation-Title>App Name</Implementation-Title>
<Implementation-Version>0.1.0</Implementation-Version>
<Application-Name></Application-Name>
<Created-By>1.8.0_45</Created-By>
<Main-Class>package.YourClass</Main-Class>
<mode>development (or production)</mode>
<url>url of the application</url>
  1. Surround your java method with the doPrivileged
  2. Be sure that your browser has the java plugin enabled
  3. Put your http path of your web app in the java exception list
  4. If your url has _ (underscore/underline) probably it won't be recognized.
  5. Try to move your .jar to the same folder of your html, not using the /applet folder.
  6. Take a look on this post, I was having a similar issue.

Remember, this error saying that 'is not a function' is because your .jar is not loading - or you made something wrong with the js syntax, what I don't think so.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.