日期:2014-05-20  浏览次数:20951 次

JRE 1.6.0_22 签名jar包里调用未签名jar包类异常
一个很简单的applet,代码(ArcTest.java以及mix.html)附后,其中ArcTest类导出为mix.jar包,MANIFEST.MF文件内容如下:

Manifest-Version: 1.0
Main-Class: ArcTest

另外需要log4j的jar包。

如果不对mix.jar进行签名,则程序运行没有问题。

问题是对mix.jar进行了签名,而log4j的jar包是没有签名认证的,就会弹出对话框,提示是否阻止运行,选择是后,出现了异常“java.lang.SecurityException: trusted loader attempted to load sandboxed resource from file:/D:/Practice/Java/test/bin/mix_signed/log4j-1.2.16.jar”,查询官方文档,http://download.oracle.com/javase/6/docs/technotes/guides/jweb/mixed_code.html#trusted_library,修改MANIFEST.MF文件,加上一句“Trusted-Library: true”,允许加载未签名的jar包。但是这时出现了另外一个异常:

java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at ArcTest.<clinit>(ArcTest.java:48)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 16 more
Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/apache/log4j/Logger

在官网论坛上发现了一个同主题的帖子,但是没有解决方案,http://forums.oracle.com/forums/thread.jspa?messageID=5203154, 大家看看这应该怎么解决?谢谢。

注意:这个问题需要JRE1.6 19以后的版本,这是因为在这个版本加了关于安全的一个enhanccement。

---- 附代码 1 ArcTest.java ----

/*
 * @(#)ArcTest.java 1.5 98/06/29
 *
 * Copyright (c) 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER