NoClassDefFoundError的使用JDBC的applet [英] NoClassDefFoundError with jdbc applet

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

问题描述

我创建使用Eclipse的applet:

 包贵;
公共类MyApplet扩展JApplet的{

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

所以我创建这样的HTML,在同一文件夹中的jar:

 < APPLET code =gui.MyApplet.classWIDTH =650HEIGHT =650ARCHIVE =proj.jar,myApplet.jar,firebirdsql- full.jar>
    &所述; A HREF =htt​​p://java.com/en/download/index.jsp>的Java&下; / A>
< / APPLET>

我也试图改变在存档属性的jar命令。

不过我一直在接收(Java控制台)以下错误:

 异常螺纹线程applet的gui.MyApplet.class-2java.lang.NoClassDefFoundError的:无法初始化类org.firebirdsql.jdbc.FBDriver
    在java.lang.Class.forName0(本机方法)
    在java.lang.Class.forName(来源不明)
    在db.DAO.getDBConnection(DAO.java:45)
    在db.MyDAO.init preparedStatements(MyDAO.java:37)
    在db.MyDAO<&初始化GT;(MyDAO.java:33)
    在db.MyDAO.getInstance(MyDAO.java:27)
    在model.Controller<&初始化GT;(Controller.java:27)
    在gui.MyApplet.getJTabbedPane(MyApplet.java:81)
    在gui.MyApplet.getJContentPane(MyApplet.java:69)
    在gui.MyApplet.init(MyApplet.java:52)
    在sun.plugin2.applet.Plugin2Manager $ AppletExecutionRunnable.run(来源不明)
    在java.lang.Thread.run(来源不明)

我缺少的东西吗?

编辑:

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

 异常螺纹线程applet的gui.MyApplet.class-1
java.lang.ExceptionInInitializerError
    在java.lang.Class.forName0(本机方法)
    在java.lang.Class.forName(来源不明)
    在db.DAO.getDBConnection(DAO.java:45)
    在db.MyDAO.init preparedStatements(MyDAO.java:37)
    在db.MyDAO<&初始化GT;(MyDAO.java:33)
    在db.MyDAO.getInstance(MyDAO.java:27)
    在model.Controller<&初始化GT;(Controller.java:27)
    在gui.MyApplet.getJTabbedPane(MyApplet.java:81)
    在gui.MyApplet.getJContentPane(MyApplet.java:69)
    在gui.MyApplet.init(MyApplet.java:52)
    在sun.plugin2.applet.Plugin2Manager $ AppletExecutionRunnable.run(来源不明)
    在java.lang.Thread.run(来源不明)
java.security.AccessControlException:引起拒绝访问(java.util.PropertyPermission FBLog4j读)
    在java.security.AccessControlContext.checkPermission(来源不明)
    在java.security.AccessController.checkPermission(来源不明)
    在java.lang.SecurityManager.checkPermission(来源不明)
    在java.lang.SecurityManager.checkPropertyAccess(来源不明)
    在java.lang.System.getProperty(来源不明)
    在org.firebirdsql.logging.LoggerFactory.getLogger(LoggerFactory.java:36)
    在org.firebirdsql.logging.LoggerFactory.getLogger(LoggerFactory.java:72)
    在org.firebirdsql.jdbc.FBDriver< clinit>(FBDriver.java:63)
    ... 12更多


解决方案

现在我们所看到的第二个堆栈跟踪,很清楚发生了什么:JDBC驱动程序试图使用log4j的日志记录。它试图从驱动程序类的静态初始化系统属性得到记录参数,它的失败,因为未签名的Applet没有权限来读取系统属性。

您可以登录您的小程序和属性(java.util.PropertyPermission FBLog4j读)授予,但在所有诚实,这不是一个好兆头;我希望它尽快抛出一些其他的安全异常为你解决了这个问题之一。如果该驱动程序尚未写入到从applet工作,很可能这将是一个傻瓜的差事尝试。

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

解决方案

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.

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

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