Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java applet with init() in a package?

Tags:

java

applet

I'm wondering if you can put the main class (or the class with the init method, whatever) inside a package and still have it run in a browser? Most of the time I put my applets into the (default package) but my applet here is in a package, so can I still embed it into the webpage?

I've googled it with little results. Say I've got MyApplet.class in a directory called app in the jar file called MyApp.jar.

I've tried these with no success:

<applet archive="MyApp.jar" code="MyApplet.class">
<applet archive="MyApp.jar" code="app/MyApplet.class">
<applet archive="MyApp.jar" code="/app/MyApplet.class">
<applet archive="MyApp.jar/app/" code="MyApplet.class">
<applet archive="MyApp.jar" codebase="app/" code="MyApplet.class">

Each of these gives me a ClassNotFoundException.

Thanks in advance.

like image 944
Bai Li Avatar asked Mar 08 '09 00:03

Bai Li


1 Answers

The archive attribute should contain the file name of the jar, and it should be placed in the same directory as the web page.

The class file in the code attribute should contain the fully qualified class name separated by forward slashes to indicate the directory structure.

Therefore, in your list of trials attempted, trial 2 should succeed, provided that MyApp.jar is actually present along side the html page. Additionally, MyApp.jar should contain the 'app' directory in the root, which should contain the MyApplet classfile. Don't forget to have MyApplet class itself in the app package.

You could take a look at this page for reference.

like image 152
Vineet Reynolds Avatar answered Sep 30 '22 05:09

Vineet Reynolds