java – 带有jdbc applet的NoClassDefFoundError
作者:互联网
我使用Eclipse创建了一个applet:
package gui;
public class MyApplet extends JApplet {
这个小程序需要两个外部jar:proj.jar和firebirdsql-full.jar(jdbc)
因此,我在与jars相同的文件夹中创建了这样的HTML:
<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顺序.
但是我继续收到以下错误(在java控制台中):
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)
我错过了什么吗?
编辑:
不知何故,在调试时,我还收到了一个不同的堆栈跟踪:
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进行日志记录.它试图从驱动程序类的静态初始化程序中的系统属性获取日志记录参数,并且它失败了,因为未签名的applet没有读取系统属性的权限.
您可以签署您的applet并将该属性(java.util.PropertyPermission FBLog4j读取)授予它,但是老实说,这不是好兆头;一旦你修复了这个问题,我希望它会抛出一些其他的安全例外.如果没有编写这个驱动程序来从applet工作,那么它很可能是一个傻瓜的差事.
标签:java,jdbc,firebird,applet,noclassdeffounderror 来源: https://codeday.me/bug/20190826/1728995.html