I have a java applet that I would like to include in my ASP.NET page. The applet works on a regular old HTML page. When I try to include the applet in my ASP.NET page however, Java appears to start up (it shows the Java logo and the spinny blue circle), but an exception occurs for my main class:
load: class com.myclass.Main.class not found.
java.lang.ClassNotFoundException: com.myclass.Main.class
I am putting the applet in the page with the following code –
<applet
code="com.xyz.Main.class"
width="500" height="500"
archive="MyJar.jar"
>
<param name="aParam" value="SomeValue"/>
</applet>
Note, this is exactly the same tag that I use to put the applet into a plain HTML page. I’m guessing that the reason for the class not found exception is that when ASP compiles the page it puts it somewhere else? If so, where? Note that I still have not actually deployed this page to a web server, it’s just running locally on my development machine.
Why not simply specify an absolute URI/oath to your applet with the codebase attribute? That way you would not have to worry about the vagaries of relative pathing of different systems.
Also see here for a longer explanation. Excerpt:
Specifying the Applet Directory
By default, a browser looks for an applet’s class and archive files in the same directory as the HTML file that has the tag. (If the applet’s class is in a package, then the browser uses the package name to construct a directory path underneath the HTML file’s directory.) Sometimes, however, it’s useful to put the applet’s files somewhere else. You can use the CODEBASE attribute to tell the browser in which directory the applet’s files are located:
If aURL is a relative URL, then it’s interpreted relative to the HTML document’s location. By making aURL an absolute URL, you can load an applet from just about anywhere — event from another HTTP server.