jasperreport-applet缺少net\sf\jasperreports\engine\print\JRPrinterAWT$1.class

最近使用JasperReport做报表,要求能直接打印,参照官方Demo写了个打印的applet,用如下方式使用时,Java控制台报异常:类未定义net\sf\jasperreports\engine\print\JRPrinterAWT$1.class,从jasperreports-3.7.4.jar中将该类拷贝到jasperreports-applet-3.7.4.jar,问题解决。
页面中用如下方式引用:
<APPLET name="printApplet" CODE="PrinterApplet.class" CODEBASE="../print"
        ARCHIVE="jasperreports-applet-3.7.4.jar,commons-collections-2.1.1.jar,commons-logging-1.0.4.jar" WIDTH="0" HEIGHT="0"/>

打印的applet代码如下:
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.util.JRLoader;

import javax.swing.*;
import java.applet.Applet;
import java.net.MalformedURLException;
import java.net.URL;

public class PrinterApplet extends Applet {
    public PrinterApplet() {
        super();
    }

    public void init() {
    }

    public void print(String strUrl) {
        URL url = null;
        JasperPrint jasperPrint = null;
        if (strUrl != null) {
            try {
                url = new URL(getCodeBase(), strUrl);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            if (url != null) {
                try {
                    jasperPrint = (JasperPrint) JRLoader.loadObject(url); //发送对象请求,获得JasperPrint对象
                } catch (Exception e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(this, "获取打印内容出错!");
                }
                if (jasperPrint != null) {
                    final JasperPrint print = jasperPrint;
                    new Thread(new Runnable() {
                        public void run() {
                            try {
                                JasperPrintManager.printReport(print, true);
                            } catch (Exception e) {
                                e.printStackTrace();
                                JOptionPane.showMessageDialog(null, "请检查系统环境并确认打印机工作正常!");
                            }
                        }
                    }).start();
                } else {
                    JOptionPane.showMessageDialog(this, "没有打印内容!");
                }
            } else {
                JOptionPane.showMessageDialog(this, "URL路径不正确!");
            }
        } else {
            JOptionPane.showMessageDialog(this, "URL路径不正确!");
        }
    }
}

你可能感兴趣的:(java,thread,.net,工作,swing)