3

I created an applet using Eclipse:

package gui;
public class MyApplet extends JApplet {

This applet needs two external jar's: proj.jar and firebirdsql-full.jar (jdbc)

Therefore I created the HTML like this, in the same folder as the jars:

<APPLET CODE="gui.MyApplet.class" width="650" height="650" ARCHIVE="proj.jar,myApplet.jar,firebirdsql-full.jar">
    <a href="http://java.com/en/download/index.jsp">Java</a>
</APPLET>

I also tried to change the jar order in the ARCHIVE attribute.

However I keep on receiving the following error (in the java console):

Exception in thread "thread applet-gui.MyApplet.class-2" java.lang.NoClassDefFoundError: Could not initialize class org.firebirdsql.jdbc.FBDriver
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at db.DAO.getDBConnection(DAO.java:45)
    at db.MyDAO.initPreparedStatements(MyDAO.java:37)
    at db.MyDAO.<init>(MyDAO.java:33)
    at db.MyDAO.getInstance(MyDAO.java:27)
    at model.Controller.<init>(Controller.java:27)
    at gui.MyApplet.getJTabbedPane(MyApplet.java:81)
    at gui.MyApplet.getJContentPane(MyApplet.java:69)
    at gui.MyApplet.init(MyApplet.java:52)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Am I missing something?

Edit:

Somehow, while debugging this, I also received a different stacktrace:

Exception in thread "thread applet-gui.MyApplet.class-1" 
java.lang.ExceptionInInitializerError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at db.DAO.getDBConnection(DAO.java:45)
    at db.MyDAO.initPreparedStatements(MyDAO.java:37)
    at db.MyDAO.<init>(MyDAO.java:33)
    at db.MyDAO.getInstance(MyDAO.java:27)
    at model.Controller.<init>(Controller.java:27)
    at gui.MyApplet.getJTabbedPane(MyApplet.java:81)
    at gui.MyApplet.getJContentPane(MyApplet.java:69)
    at gui.MyApplet.init(MyApplet.java:52)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission FBLog4j read)
    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.checkPropertyAccess(Unknown Source)
    at java.lang.System.getProperty(Unknown Source)
    at org.firebirdsql.logging.LoggerFactory.getLogger(LoggerFactory.java:36)
    at org.firebirdsql.logging.LoggerFactory.getLogger(LoggerFactory.java:72)
    at org.firebirdsql.jdbc.FBDriver.<clinit>(FBDriver.java:63)
    ... 12 more
Schiavini
  • 2,869
  • 2
  • 23
  • 49

2 Answers2

4

Now that we see the second stack trace, it's clear what's happening: the JDBC driver is trying to use Log4J for logging. It's trying to get logging parameters from a system property in the static initializer of the driver class, and it's failing because unsigned applets don't have permission to read system properties.

You can sign your applet and grant that property (java.util.PropertyPermission FBLog4j read) to it, but in all honesty, this does not bode well; I'd expect it to throw some other security exception as soon as you fixed this one. If this driver hasn't been written to work from an applet, it's likely that it'll be a fool's errand trying.

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
  • 4
    Just to confirm: Jaybird (the Firebird JDBC driver) is not written with support for applets in mind; that said I created a ticket http://tracker.firebirdsql.org/browse/JDBC-254 as a reminder to investigate this, as it could also occur in other restricted environments. – Mark Rotteveel May 20 '12 at 15:26
  • Thank you guys. I will see if I can find a work around, else I'll accept your answer soon – Schiavini May 20 '12 at 21:42
  • 1
    It looks like it only happens in the latest 1.6 java versions. As this was a test applet, I solved by adding full privileges to my java.policy file: grant codeBase "http://website/path/*"{permission java.security.AllPermission;}; – Schiavini May 21 '12 at 17:20
2

Unsigned applets are running in a 'restricted' sandbox, so to speak. More info here over at Oracle's documentation: http://docs.oracle.com/javase/tutorial/deployment/applet/security.html

My guess, much like the exception says, is that FBDriver.java:63 (inside Firebird ) is doing something that the JVM won't allow.

By the way, it is a bit odd to load a JDBC driver inside an applet, but I digres..

Hans Westerbeek
  • 5,645
  • 3
  • 34
  • 35
  • 1
    +1, if only for the last sentence. I'm thinking you mean something like "An applet should not have *direct* access to the DB, for security reasons. Instead it should act via other server-side functionality that accesses the DB."? – Andrew Thompson May 21 '12 at 02:37
  • Agree with you 100%, but it is not really the topic of the question, that's why I didn't really go into detail – Hans Westerbeek May 21 '12 at 11:04