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">
Related
So I'm running into a problem here getting an applet to run. The .class file is in another directory and I've learned that you can use the codebase attribute to point to where the file is. Here is my calling code.
<applet codebase="/Cartographer/bin" code="CartographerApplet.class" width="300" height="150"></applet>
Now the .class file i'm looking for is in a package I've deemed Cartographer.
My question is, is there something I'm missing? Or is my code completely wrong? I have a hunch that I'm not doing the codebase part correctly because I don't really know how to provide a shortened path without giving the whole C:\ect\ect\ect path.
Edit: The root directory has the folder Cartographer in it which houses the java project for creating the app. So the path I have is what points to the .class file I need. I've tried using the code attribute with and without the Cartographer package attached to the beginning and I keep getting a class not found exception.
I have 2 projects: my main project in which the applet is, and a second project from which I use some classes. I added the second project to my main projects build path. But when I run my applet in Chrome, it gives an error: java.lang.NoClassDefFoundError: chapter13/MessagePanel. chapter13/MessagePanel is the class that I imported from the second project into my main project.
I call the applet like this(the html file is in the main project root folder):
<applet
code = "myapplets/DisplayMessageApp.class"
width = 250
height = 50>
</applet>
What can I do so that the applet can see the "chapter13/MessagePanel" class from the second project?
The simplest thing is to bundle all the required classes in a jar file and then specify this as the archive.
Like this:
http://docs.oracle.com/javase/7/docs/api/java/applet/Applet.html
André
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>
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
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.