Multiple Class Applet - java

Hi have the following classes for a java game that I have created:
Contents.class
Reader.class
Sokoban.class
Sokoban.class is my main class.
I'm using this applet code snippet to embed the game onto my website:
<applet code="Sokoban.class" width="350" height="350"></applet>
My classes are all in the same directory, but I get a blank screen when I try to load the html file that has the applet code.
What am I missing here?

Compose jar file from your classes and specify jar file in applet section as archive attribute. Code attribute should point to the main class.
Here is the sample for applet, composed as SokobanGame.jar:
<applet code="Sokoban"
archive="SokobanGame.jar"
width=350 height=350>
</applet>

Related

JApplet java.lang.NoClassDefFoundError: org/json/JSONException

I have this JApplet jar and tried to open it on the web.
But I keep getting this error
java.lang.NoClassDefFoundError: org/json/JSONException
I've searched the answers here and tried them, but didn't work.
Even if I already added the java-json.jar in my build path of the project.
this is my html code for running my jar file on the web
<applet archive="PDDS.jar" code="MainFrame.class" width="960" height="540">
I have two classes inside PDDS.jar, the JApplet class is the MainFrame.class, the other one is a class for connecting to the sqlite database.
Even if I already added the java-json.jar in my build path of the project.
The build path of a project has nothing to do with the runtime class path, which is set in the applet element.
So..
<applet archive="PDDS.jar" code="MainFrame.class" width="960" height="540">
Should be more like..
<applet archive="PDDS.jar java-json.jar" code="MainFrame.class" width="960" height="540">
Note also that the code attribute should best be the fully qualified name of the applet class, not the file name, so it would look like:
<applet archive="PDDS.jar java-json.jar" code="MainFrame" width="960" height="540">

working with signed applets

I would like to create and work a signed applet from an applet that I wrote. The applet itself uses a library (owlapi) that has to have the correct write rights in order to save the changes made to the owl repository.
In order to do this I should use a .policy file or signed applets. To make signed applets I followed this manual. I follow that manual on the letter, and yet it doesn't work. I get to the point where I have a signed applet and include it in the html like this:
<applet code="owlapi.LoadOntology.class" archive="owlapi/SignedLoadOntology.jar" height=100 width=1000 MAYSCRIPT>
<param NAME="archive" VALUE='owlapi/Signedowlapi-src.jar, owlapi/Signedowlapi-bin.jar'>
</applet>
When I am testing that applet with the appletviewer (which is recommended in that manual), I get the error
I thought I could solve that by manually compile the code with that library and then create a jar with all those .class files, but that didn't help:
javac -cp owlapi-src.jar:owlapic-bin.jar LoadOntology.java
jar cvf LoadOntology *.class
Does anybody know how to create such a signed applet that uses a some other jar-files?
*update: * after reading this thread, I found out that the owlapi-src and owlapi-bin jars had to be included to the applet in the html an should be signed too. I changed the code to my current testing code, but that still didn't work, since I now have again the
java.lang.SecurityException: Unable to create temporary file
which means that the code from the used owlapi library isn't found.
You probably need not include the -src jar, as I'd expect it to contain the java sources.
I do think you need to provide both your own signed jar and the signed library jar in one and the same applet parameter, as follows:
<applet code="owlapi.LoadOntology.class" height=100 width=1000 MAYSCRIPT>
<param NAME="archive"
VALUE='owlapi/SignedLoadOntology.jar, owlapi/Signedowlapi-bin.jar'>
</applet>

JApplet works in applet viewer, not in HTML page

This topic has been covered in one form or another but none of the other threads have been able to help. My issue is very similar to this post, I am making a JUNG graph with added functionality, but none of the solutions helped:
JApplet fails to run in HTML page
I had a Java application that I converted to a JApplet. The JApplet works fine in the applet viewer in Eclipse but will not work when I try to open it in a webpage (I have tried IE, FireFox, and Chrome). I have my HTML page and archive folder both in the same directory. When I load the HTML page it just brings up nothing.
Here is my html code:
<html>
<title>Applet</title>
<head>
</head>
<body>
<applet code="prerna.blueprint.main.BPTester.class"
archive="applet1.jar"
width="800" height="800">
</applet>
</body>
</html>
When I try to have code="BPTester.class" it gives java.lang.ClassNotFoundException: BPTester.class but when I use code="prerna.blueprint.main.BPTester.class" it gives me no errors just nothing happens. (prerna/blueprint/main/BPTester.class is the file path in my src folder). I exported my Java project as a runnable jar file, is this correct? I created a simple JApplet that worked fine when I did all the same steps but it won't work for BPTester.class.
If I need to post my BPTester.class code I can.
I don't understand why I can't view the JApplet in a webpage, any help is greatly appreciated.
What ended up working for me was adding every single jar I used in the japplet to the HTML archive tag then had to sign every jar. I then had an issue with accessing my database within the applet1.jar so I just put an absolute path for its location.
java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
The applet needs to be digitally signed (by you) and trusted (by the end user, when prompted) before it can obtain such information. Given this applet is being deployed using a traditional applet element (i.e. not using web start), all jars need to be signed.
You need to sign every jar. You can sign all the jars with the jarsigner utility. Example:
jarsigner.exe "nameofthejar.jar" "alias"
Remove .class from the end. You either use a file path with slashes and .class at the end or you only use periods and no .class at the end.
Try turning on tracing in the java control panel. It will then produce a log file in the following path that may help: %USERPROFILE%\AppData\LocalLow\sun\java\Deployment\log

Trying to load java applet via html file

Directory is like so:
test.html
blah
hmmm
Inside "blah" we have all the applet files, including blahBlah.class. Inside "hmmm" are a few more more class files that were taken from a library or something, they are used by the project also.
I write in test.html...
<applet name="blah" code="/blahBlah.class" codebase="blah"></applet>
(along with every other variation I could think of)
Farthest I've gotten is:
java.lang.NoClassDefFoundError: blahBlah (wrong name: blah/blahBlah)
Now inside blahBlah.java, we have:
package blah;
I'm not sure if it's related.
Also wondering if it may be necessary to place the project in a jar file and set the archive attribute of the applet?
The real files are not blah and blahBlah, but I've replaced the names faithfully.
java.lang.NoClassDefFoundError: blahBlah (wrong name: blah/blahBlah)
This basically means that it's been executed as
java blahBlah
instead of
java blah.blahBlah
In other words, your code attribtue is wrong. It has to be
<applet name="blah" code="blah/blahBlah.class" />
or just by FQN (see also Andrew's comment)
<applet name="blah" code="blah.blahBlah" />
The codebase defaults to the current folder, which is fine in this case, so it's removed. An alternative is to put it in another folder, such as /applet or something. You should at least not use a package folder as code base, but instead the package root.

My Applet will not run in a browser

Can anyone help me out. I've written a program that controls the heating system in an imaginery house, an applet actually. it runs fine in netbeans but i cant get it to run as an applet in a browser, can anyone help me out please, I linked to a zip folder of all my code...
http://dl.dropbox.com/u/47863/Heating%20System.zip
http://alcaeos.com/applet/classes/MyHomeHeating.class -> 404.
Or to put that another way.
The applet element is telling the JRE to look for the class at the URL mentioned above.
The class is not at that location. (Neither is it in the same directory as the HTML.)
Where is the class file?
BTW: Typical bloody Netbeans generated code (/HTML). When what it generates is not invalid, it is redundant.
code="MyHomeHeating.class" The code attribute should not include .class.
<HR WIDTH="100%"> An HR element normally spans the entire width of the page.
You need to compile your applet into .class files (not .java files like you have in the ZIP; those are source code) and embed it into an HTML page. You can use the tag in HTML to do these; read more here: http://www.echoecho.com/applets01.htm

Categories

Resources