• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem Deploying Applet

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an applet that contains about 30 different class files, all held within two different packages (userInterface and guts), as well as some image files. It also uses an external jar (mysql-connector).

Im having problems viewing it within a browser, though it runs fine in Eclipse. I'm not trying to run it off of a server yet, I'm just putting the project jar file (new.jar) and the html page I create in the same directory (C:/Users/Jeff/Desktop/applet/) on my system, and running it from there.

The class which extends JApplet is in the userInterface package, and is called Main.

Here is my HTML:

<html>
<title>My Applet</title>
<body>
<applet archive='new.jar',
code='userInterface.Main.class',
width=500,
height=500 />
</body>
</html>

I've read through quite a few posts from others experiencing similar issues, but still haven't had any luck after trying to implement their solutions

Thanks for any help you can offer

*EDIT*: I just tried moving 'Main.class' from my jar into a directory (/applet/userInterface/) and changing my html code line to code='userInterface.Main', and am now getting the following errors:

java.lang.RuntimeException: java.lang.ExceptionInInitializerError
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkExit(Unknown Source)
at java.lang.Runtime.exit(Unknown Source)
at java.lang.System.exit(Unknown Source)
at guts.DBHelper.getConnection(DBHelper.java:43)
at userInterface.Main.<clinit>(Main.java:29)
... 21 more
Exception: java.lang.RuntimeException: java.lang.ExceptionInInitializerError

Could this be due to problems connecting to remote db?

I added a java.policy file with:
grant {
permission java.security.AllPermission;
};
to the /applet/ directory, so hopefully this portion of the problem should be fixed.
 
Jeff Terry
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think my applet/jar/html's are all in place now, but I can't get past the security errors I am getting when attempting to connect to remote databases.

Reading up on things, I thought the solution may be a crossdomain.xml file placed on the server I was attempting to access. I created one, but now, when I try to run the applet, it just freezes and gives me a black screen (firefox & IE). Chrome still gives errors stating: "Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: Could not initialize class userInterface.Main" (so maybe I shouldn't be so confident in how I set up the applet? Still something wrong? The db connection is occurring during Main's init() though)

*EDIT*: Just found a previous post referring to instructions at "http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html". Checking it out right now.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the guts.DBHelper.getConnection method really call System.exit? That wouldn't work in an applet, and is thus not allowed.
 
Jeff Terry
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it was (which it definitely should not have been). I have removed that line and then got the following error:

java.lang.RuntimeException: java.lang.NoClassDefFoundError: userInterface/ImageComponent
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: userInterface/ImageComponent
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: userInterface.ImageComponent
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 20 more
Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: userInterface/ImageComponent

So, after taking the ImageComponent class out of the jar and into the /applet/userInterface directory, I then got errors of other classes not being found. I eventually just extracted everything from the jar straight into the /applet/ directory. Errors are now gone, but the applet just crashes on load and doesn't give a chance for any errors (Firefox: black screen applet, IE: frozen Java loader).

Is this the right way to handle applet file structure? If so, whats the point or the "archive" tag and a jar? Doesn't seem like it was ever using it anyway (though I'm sure my assumptions are incorrect).
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it's not necessary to deploy loose class files - the point of jar files is to have to deal with a single file only. My guess would be that the internal structure of it was somehow incorrect.
 
Jeff Terry
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, some progress has been made. Following Ulf's suggestions that the structure was wrong, I stopped using the open source Fat Jar to create my jar file, and just used Eclipses regular Export -> Jar File. I wasn't able to get this to also jar up the external mysql-connector jar, so I just copied the mysql jar "com" folder directly into my /applet/ directory.

I was still unable to access the database, until I followed the directions at http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html to self-sign my applet. Hooray! Now the connection to the remote database is successful.

Now the problem I am running into is reading images into the applet from my jar. I am getting the following error:
java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at userInterface.ImageComponent.<init>(ImageComponent.java:34)
at userInterface.Main.init(Main.java:100)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.IllegalArgumentException: input == null!

My ImageComponent code:
I was using this code before deployment for reading in images, but I guess its not very applet friendly?
ClassLoader cL = Thread.currentThread().getContextClassLoader();
InputStream iS = ClassLoader.getSystemResourceAsStream(name);
image = ImageIO.read(iS);

So I changed it to:
URL urlResource = getClass().getResource(name);
System.out.println("Got resource...");
image = Toolkit.getDefaultToolkit().getImage(urlResource);
where name is just a String, i.e. "background-1.gif", "background-2.gif", etc.

The part that seems weird to me is, in my Eclipse project all the images are found in the /images/ directory, however, when I export the project to a jar, they are all dumped directly within the top level of the jar (no images directory). Do you think this could be the cause of the problem? Or am I reading them in incorrectly?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both approaches should work, provided you get the directories sorted out. I'd prefer using ImageIO, though.

It's hard to say what Eclipse does. The only important thing is how the files are layed out in the server directories; that's what matters. IDEs are notorious for not working exactly like an actual server.

I definitely would not keep the images in a jar file, but as loose files.
 
Jeff Terry
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I put the images in the base /applet/ directory, and then after changing my code to retrieve the images to

//where thisApplet is a static reference to the "Main" applet class itself:
Main.thisApplet.getImage(Main.thisApplet.getDocumentBase(),imageName))

and now its all working!

Thanks for your help Ulf

 
reply
    Bookmark Topic Watch Topic
  • New Topic