java applet class not found exception in the chrome browser - java

I am trying to run Java applet using Google Chrome browser. Everytime I am getting no class found exception. Here is my code.
HelloWorld.java
package my.first.pack;
import java.applet.Applet;
import java.awt.*;
public class HelloWorld extends Applet {
/**
*
*/
private static final long serialVersionUID = 2741715258812838900L;
public void paint(Graphics g) {
g.drawString("welcome", 150, 150);
}
}
Hello.html
<applet code="my.first.pack.HelloWorld" width="300" height="300">

Sign your applet and all the .jar dependencies with a certificate.
Populate your manifest with all the tags mentioned below (it's in xml because I use maven, you can write in the way you prefer)
<codebase>http://location.of.your.jar/</codebase>
<permissions>all-permissions</permissions>
<Application-Library-Allowable-Codebase>http://location.of.your.jar/</Application-Library-Allowable-Codebase>
<Manifest-Version>1.0</Manifest-Version>
<Implementation-Title>App Name</Implementation-Title>
<Implementation-Version>0.1.0</Implementation-Version>
<Application-Name></Application-Name>
<Created-By>1.8.0_45</Created-By>
<Main-Class>package.YourClass</Main-Class>
<mode>development (or production)</mode>
<url>url of the application</url>
Surround your java method with the doPrivileged
Be sure that your browser has the java plugin enabled
Put your http path of your web app in the java exception list
If your url has _ (underscore/underline) probably it won't be recognized.
Try to move your .jar to the same folder of your html, not using the /applet folder.
Take a look on this post, I was having a similar issue.
Remember, this error saying that 'is not a function' is because your .jar is not loading - or you made something wrong with the js syntax, what I don't think so.

Related

Why do I get "LoadLibrary failed with error 1114: a dynamic link library (DLL) initialization routine failed"?

When I run my java application program an error window appears saying that
"LoadLibrary failed with error 1114: a dynamic link library (DLL) >initialization routine failed".
I have tested my code on a different machine and it worked perfectly.The program shows a PApplet window with a map inside.However, Running the code on my laptop, the PApplet appears and all of the sudden the DLL error stops the rest from being shown.
What the problem could be and how can I fix it?
Here is the code I am trying to run. It is worth to mention that it runs successfully if I remove what's inside the setup() method.
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.providers.Google;
import de.fhpotsdam.unfolding.utils.MapUtils;
import processing.core.PApplet;
public class LifeExpectancy2 extends PApplet {
UnfoldingMap map;
public void setup()
{
size(800,600,OPENGL);
map = new UnfoldingMap (this, 50, 50, 700, 500, new Google.GoogleMapProvider());
MapUtils.createDefaultEventDispatcher (this, map);
}
public void draw()
{
}
}
I had the same issue after I installed my Netbeans to build some projects in PHP and it was fixed changing some graphics options in the control painel of my Windows 10.
Take a look on this video and see if it fixs your issue as well:
Windows 10 - Java Loadlibrary Error 1114
I hope it can be helpful!
Which Unfolding version did you download? You seem to use some Java IDE (and not Processing's one) so you need the Unfolding-for-Eclipse distribution which includes all needed native libraries (i.e. also the DLL in question).
For the records, the DLL is the native library for Windows OS to bind Java to the OpenGL API (JOGL).

Deploying a JApplet: ClassNotFoundException

Edit 2: I created a html in the root directory and placed the jar file in the same place, I could then get the applet to run (though I had some issues with self-signed security). This tells me the problem is in the applet code. Any ideas why it wouldn't find the class when if I can remove the codebase attribute it runs correctly?
Edit 1: I have updated the entry point to remove the frame. I also tested with the HelloWorld applet and still received the same error.
I'm fairly new to Java so I'll try to explain my problem as clearly as I can and with plenty of detail. If I miss anything please let me know. I'm also aware that this problem is frequently asked about on here, I've done a fair bit of research and found conflicting responses and nothing that worked.
I have developed a JApplet in eclipse, exported a jar file for the project and am attempting to deploy it on my website. However, when I attempt to view the applet online I get the error: ClassNotFoundException. It is probably also worth mentioning that I am trying to deploy this JApplet through wordpress.
Here is the html code I'm using to deploy:
<applet code = 'gui.ConverterGUI.class'
codebase = 'http://www.myurl.co.uk/Java/'
archive = 'AConverter.jar'
width = 800
height = 600>
<param name="permissions" value="all-permissions" />
</applet>
My applet has a few packages and classes which I think I have set up and exported correctly, but incase that is causing problems, here is my main entry point:
public class ConverterGUI extends JApplet {
// Current program ver.
public static final double VERSION = 0.0;
public void init() {
// Make it look nicer.
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {
e.printStackTrace();
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private void createAndShowGUI() {
System.out.println("Created GUI on EDT? "+
SwingUtilities.isEventDispatchThread());
//JFrame f = new JFrame("Converter GUI");
ResultDisplay resultDisplay = new ResultDisplay();
getContentPane().add(resultDisplay, BorderLayout.CENTER);
getContentPane().add(new InputFields(resultDisplay), BorderLayout.NORTH);
}
}
This is my project layout.
I've exported the jar using Eclipse, I've got the impression that this means it has been signed properly already, but if this is not the case and it is causing issues, I'd appreciate being pointed in the right direction to do this (I do have eclipse set up with the JDK rather than JRE).
The issue was in the html code and the way wordpress was interpreting it. For future reference, I fixed the issue by removing the lines from the html code and using double quotes, as follows:
<applet code = "gui.ConverterGUI.class" codebase="http://www.myurl.co.uk/Java/" archive="AConverter.jar" width=800 height=600><param name="permissions" value="all-permissions" /></applet>
Nonetheless I did get some useful advice here. Thanks all.

How can I call Java applet methods with Javascript?

i've created a java applet last year for a socket connection from a web application to a local running java server. it worked fine.
since the last java updates (7 r21 i guess), i cannot access the methods within javascript anymore. Right now, i reduced the applet to a test applet (without the doPriviligedAction methods) but even this does not work anymore.
The current code is like
import java.applet.*;
public class socketApplet extends Applet {
public void init() {
System.out.println("Applet initialisiert.");
}
public void start() {
System.out.println("Applet gestartet.");
}
public void paint() {
System.out.println("Applet aktualisiert.");
}
public void stop() {
System.out.println("Applet angehalten.");
}
public void destroy() {
System.out.println("Applet beendet.");
}
public String testApplet() {
System.out.println("Applet getestet.");
return "Yep, I'm the Applet.";
}
}
Before the update i could access methods like testApplet() in javascript like this:
document.socketApplet.testApplet();
The applet is self-signed and embedded with an applet html-tag. It is starting (the java console is opening and prints the debug messages defined in the init, start and paint methods) but i cannot access the testApplet() method. The response in Javascript is "undefined" while the applet exists.
after reading a while (a few days now...) about the new security changes, i've added a manifest.txt with the following content:
Main-Class: socketApplet
Permissions: all-permissions
Codebase: *
Trusted-Library: true
No luck with or without the Trusted-Library attribute.
What do i have to do to enable the access with javascript again?
Edit:
The implementation:
<applet id="socketApplet" width="100" height="100" archive="../../socketApplet.jar" name="socketApplet" code="socketApplet" scriptable="true">
I am testing with the newest versions of Firefox and Safari on an up to date Mac OS X machine.
Edit2:
i am creating and signing the jar like this
Edit3:
Okay, now my jar worked a few times (not in a row), i got
and in the console
But most of the time it does not work. restarting the browser, clearing caches, nothing works. going to test this on another pc now (again).
Edit4:
Okay it is running on a virtual machine with windows xp and java 32bit 7u25 - on my 64bit mac just only 1 out of 30 tries.
Okay i found the source of all evil...
it had nothing to do with the applet. the confusing situation was that it worked in firefox on windows and not in firefox on the mac (same FF versions, same java versions). Safari on my mac didn't work because the plugin was disabled...
So it was a Firefox on mac problem only. I've tested different situations and the applet worked when writing the applet code above into a html page. Before, i've created the applet dynamically (what is necessary in the software):
var applet = document.createElement('applet');
applet.archive = 'socketApplet.jar';
applet.id = 'socketApplet';
applet.name = 'socketApplet';
applet.code = 'socketApplet';
applet.scriptable = 'true';
applet.width = '0';
applet.height = '0';
document.body.appendChild(applet);
It works everywhere but not in Firefox on Mac. So as a workaround i have to embed the applet in an iframe and i have to embed the iframe dynamically. that works...
var mFrame = document.createElement('iframe');
mFrame.id = 'testFrame';
mFrame.height = '200';
mFrame.width = '400';
document.body.appendChild(mFrame);
mFrame.src = 'frame.html'; // contains the applet code
Next i am going to change the html tag to the object and embed tag for IE support. Thanks for your help Andrew Thompson!
I dislike the iframe version because the access to the applet via javascript is more complex, but it seems like there is no other way around.
I am going to submit a Mozilla bug ticket for this.
https://bugzilla.mozilla.org/show_bug.cgi?id=912880
Maybe similar to this one but another situation:
https://bugzilla.mozilla.org/show_bug.cgi?id=872969

JAVA applet Simplest program

I'm trying to run a code on lifecycle of applet as shown. This file is saved as Lifecycle.java
I compiled it by
javac Lifecycle.java
then tried to run it by
appletviewer Lifecycle.java
package APPLETS;
import java.applet.Applet;
public class Lifecycle extends Applet
{
/*
< APPLET
code = "Lifecycle.class"
height = "300"
width = "300">
< \APPLET>
*/
public void init()
{System.out.print("INIT");}
public void stop()
{System.out.print("STOP");}
public void start()
{System.out.print("Start");}
public void destroy()
{System.out.print("Destroy");}
}
APPLET is not loading then, though my code compiles successfully, no instructions are seen on command prompt. I'm just seeing a blank page with error -> Start:applet not initialized
HERE is the Lifecycle.html code-->
and here is the ERROR-
load: class APPLETS.Lifecycle.class not found.
java.lang.ClassNotFoundException: APPLETS.Lifecycle.class
The appletviewer is expecting to find HTML content so cannot parse the input file. Use appletviewer against a URL rather than a Java source file.
appletviewer is used to view applets using a URL. This URL can be in the format of a local or remote HTML document. Create a HTML document including the tag specifying your class and run the appletviewer against it.
life.html:
<APPLET CODE="APPLETS.Lifecycle" width="300" height="300"></APPLET>
then use
appletviewer life.html
The simplest folder structure for this to run is
./
|life.html
|-APPLETS
Lifecycle.class
Related: The Java Applet Viewer
Aside: Consider using the more up-to-date Swing JApplet.
Put Lifecycle.java in a folder called APPLETS, and try running:
appletviewer APPLETS.Lifecycle

ClassCastException while executing "HelloWorld" applet code

I am trying to run simple "Hello world" java applet program. But on execution applet does not appear in browser instead ClassNotFoundException occurs.
This is how I am accessing it from browser:-
<applet width="500" height="50" codebase="http://localhost:13383/tuexample/"
code="dk.certificate.demo.DemoApplet.class" >...applet..</applet>
JavaCode:-
import java.applet.Applet;
import java.awt.Graphics;
public class DemoApplet extends Applet
{
private static final long serialVersionUID = 1L;
#Override
public void paint(Graphics g)
{
g.drawString("Welcome in Java Applet.",40,20);
}
}
Exception Log:-
Java Plug-in 10.21.2.11
Using JRE version 1.7.0_21-b11 Java HotSpot(TM) Client VM
User home directory = C:\Users\rahil_khan
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
28-May-2013 14:20:51 <INFO> thread applet-dk.pbs.applet.bootstrap.BootApplet-1 - stop
28-May-2013 14:20:51 <INFO> thread applet-dk.pbs.applet.bootstrap.BootApplet-1 -
destroy
Let me finally answer this Question:
You are getting ClassNotFoundException because Applet class, it seems, can not be found in the configuration you have provided.
Your code does this: It is trying to find DemoApplet.class inside the package dk.certificate.demo inside the localhost:13383/tuexample/
So, if we consider localhost:13383/tuexample/ to be your root webapp directory called xyz then your possible file structure should be like this:
XYZ/dk/certificate/demo/DemoApplet.class which clearly does not seem to be the case.
Also make sure you have package dk.certificate.demo inside your class file which I don't see at the moment.
Now, it should be easy to fix your code from what I have explained.
In tag:
code="dk/certificate/demo/DemoApplet.class"
package dk.certificate.demo;?
dk/certificate/demo/DemoApplet.class?
By the way JApplet, swing i.o. AWT, is the better solution.
Maybe in your case the code base resides in (should be) WEB-INF/classes, which normally is notokay, as WEB-INF files should not be accessible by URL.
In fact normally a .jar is created in a separate project and deposited in the Web Contents directory.
#RaviTrivedi and #JoopEggen thanks for your support I was able to fix the problem.
Two solutions:-
DemoApplet.jar:-
I created jar(DemoApplet.jar) of my applet code(DemoApplet.java) and
placed it in AppletDemo\WebContent\lib folder.
I moved classes folder
from AppletDemo\WebContent\WEB-INF\classes
to AppletDemo\WebContent\classes
And from login.jsp I made call to applet in following way:-
<!-- DemoApplet.jar -->
<applet
width="500"
height="50"
codebase="http://localhost:8080/AppletDemo"
archive="lib/demoApplet.jar"
code=dk.certificate.demo.DemoApplet.class >...applet..</applet>
<!-- classes -->
<applet
width="500"
height="50"
codebase="http://localhost:8080/AppletDemo/classes"
code=dk.certificate.demo.DemoApplet.class >...class...applet..</applet>
It worked both ways.
Thanks a lot. :D

Categories