一个很简单的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
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */import java.awt.*;
import java.awt.event.*;
import java.applet.*;import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;/**
 * An interactive test of the Graphics.drawArc and Graphics.fillArc routines.
 * Can be run either as a standalone application by typing "java ArcTest" or as
 * an applet in the AppletViewer.
 */
public class ArcTest extends Applet {
ArcControls controls; // The controls for ing and filling arcs
ArcCanvas canvas; // The drawing area to display arcs static Logger logger = Logger.getLogger(ArcTest.class.getName());

public void init() {
setLayout(new BorderLayout());
canvas = new ArcCanvas();
add("Center", canvas);
add("South", controls = new ArcControls(canvas));
}  public void destroy() {
remove(controls);
remove(canvas);
} public void start() {
PropertyConfigurator.configure("./log4j.properties");
logger.debug("this is a debug message");
logger.info("this is a info message");
logger.warn("this is a warn message");
logger.error("this is a error message");
logger.fatal("this is a fatal message");
controls.setEnabled(true);
}  public void stop() {
controls.setEnabled(false);
} public void processEvent(AWTEvent e) {
if (e.getID() == Event.WINDOW_DESTROY) {
System.exit(0);
}
} public static void main(String args[]) {
Frame f = new Frame("ArcTest");
ArcTest arcTest = new ArcTest(); arcTest.init();
arcTest.start(); f.add("Center", arcTest);
f.setSize(300, 300);
f.show();
} public String getAppletInfo() {
return "An interactive test of the Graphics.drawArc and \nGraphics.fillArc routines. Can be run \neither as a standalone application by typing 'java ArcTest' \nor as an applet in the AppletViewer.";
}
}class ArcCanvas extends Canvas {
int startAngle = 0;
int endAngle = 45;
boolean filled = false;
Font font; public void paint(Graphics g) {
Rectangle r = getBounds();
int hlines = r.height / 10;
int vlines = r.width / 10; g.setColor(Color.pink);
for (int i = 1; i <= hlines; i++) {
g.drawLine(0, i * 10, r.width, i * 10);
}
for (int i = 1; i <= vlines; i++) {
g.drawLine(i * 10, 0, i * 10, r.height);
} g.setColor(Color.red);
if (filled) {
g.fillArc(0, 0, r.width - 1, r.height - 1, startAngle, endAngle);
} else {
g.drawArc(0, 0, r.width - 1, r.height - 1, startAngle, endAngle);
} g.setColor(Color.black);
g.setFont(font);
g.drawLine(0, r.height / 2, r.width, r.height / 2);
g.drawLine(r.width / 2, 0, r.width / 2, r.height);
g.drawLine(0, 0, r.width, r.height);
g.drawLine(r.width, 0, 0, r.height);
int sx = 10;
int sy = r.height - 28;
g.drawString("S = " + startAngle, sx, sy);
g.drawString("E = " + endAngle, sx, sy + 14);
} public void redraw(boolean filled, int start, int end) {
this.filled = filled;
this.startAngle = start;
this.endAngle = end;
repaint();
}
}class ArcControls extends Panel implements ActionListener {
TextField s;
TextField e;
ArcCanvas canvas; public ArcControls(ArcCanvas canvas) {
Button b = null; this.canvas = canvas;
add(s = new TextField("0", 4));
add(e = new TextField("45", 4));
b = new Button("Fill");
b.addActionListener(this);
add(b);
b = new Button("Draw");
b.addActionListener(this);
add(b);
} public void actionPerformed(ActionEvent ev) {
String label = ev.getActionCommand(); canvas.redraw(label.equals("Fill"),
Integer.parseInt(s.getText().trim()),
Integer.parseInt(e.getText().trim()));
}
}---- 附代码 2 mix.html ----
<html><head>
<meta http-equiv="content-type" content="text/html; charset=GB2312">
  
      <title>Arc Test (1.1)</title>
<meta name="collection" content="exclude">
  </head><body>
      <h1>Arc Test (1.1)</h1>
      <hr>
      <applet code=ArcTest archive="./mix.jar,./log4j-1.2.16.jar" height="400" width="400">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
      </applet>
      <hr>
</body></html>