tags:

views:

528

answers:

3

Hi.

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.

+1  A: 

I'm not sure, but have you tried like this?:

<applet archive="MyApp.jar" code="MyApplet">
rogeriopvl
+3  A: 

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.

Vineet Reynolds
+2  A: 

Well you list the package in a dotted form and you don't put the '.class' on the end.

<applet code="packagefolder1.packagefolder2.MyApplet" archive="folder1/folder2/MyApp.jar">

</applet>
James