NoClassDefFoundError with jdbc applet

不羁岁月 提交于 2019-12-19 09:26:41

问题


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

回答1:


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.




回答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..



来源:https://stackoverflow.com/questions/10673119/noclassdeffounderror-with-jdbc-applet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!