带有 jdbc 小程序的 NoClassDefFoundError [英] NoClassDefFoundError with jdbc applet

查看:26
本文介绍了带有 jdbc 小程序的 NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Eclipse 创建了一个小程序:

I created an applet using Eclipse:

package gui;
public class MyApplet extends JApplet {

这个小程序需要两个外部 jar:proj.jar 和 firebirdsql-full.jar (jdbc)

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

因此,我在与 jars 相同的文件夹中创建了这样的 HTML:

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>

我还尝试更改 ARCHIVE 属性中的 jar 顺序.

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

但是我一直收到以下错误(在 java 控制台中):

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)

我错过了什么吗?

不知何故,在调试时,我也收到了不同的堆栈跟踪:

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

推荐答案

现在我们看到了第二个堆栈跟踪,很清楚发生了什么:JDBC 驱动程序正在尝试使用 Log4J 进行日志记录.它试图从驱动程序类的静态初始值设定项中的系统属性获取日志参数,但由于未签名的小程序没有读取系统属性的权限而失败.

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.

您可以签署您的小程序并将该属性(java.util.PropertyPermission FBLog4j 读取)授予它,但老实说,这不是好兆头;我希望它在您修复此异常后立即抛出其他一些安全异常.如果这个驱动程序没有被编写为在小程序中工作,那么它很可能是白费力气的尝试.

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.

这篇关于带有 jdbc 小程序的 NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆