- 下载古老的IReport报表编辑器。
链接:https://community.jaspersoft.com/project/ireport-designer/releases
,最后打包时间为2014年5月,最终版本停留在v5.6.0。 - 由于IReport最高支持jdk7,所以一般会启动失败,推荐下载7u80,便可顺利启动:
编辑配置文件:【D:\iReport-4.5.1\etc下的ireport.conf】追加一行【jdkhome="D:\Program Files\Java\jdk1.7.0_80"】。
- 准备编译与反编译:
maven-pom.xml:
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.7.0</version>
</dependency>
代码:
package comg.yang.httpstest.controller;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.engine.xml.JRXmlWriter;
import java.io.File;
/**
* @description:
* @author: Yang JX
* @since: 2021/8/14
*/
public class JasperCompile {
public static void main(String[] args) throws Exception {
compile();
decompile();
}
/**
* 从jrxml编译为jasper
*
* @throws JRException
*/
public static void compile() throws JRException {
JasperCompileManager.compileReportToFile(
"/Users/rr/Desktop/goooo/shuYe/printSendMedCfqSy.jrxml",
"/Users/rr/Desktop/goooo/shuYe/printSendMedCfqSy.jasper"
);
}
/**
* 从jasper反编译为jrxml
*
* @throws JRException
*/
public static void decompile() throws JRException {
String sourcePath = "/Users/rr/Desktop/goooo/printSendMedCfqSyChild.jasper";
File file = new File(sourcePath);
JasperReport report = (JasperReport) JRLoader.loadObject(file);
String destinationPath = "/Users/rr/Desktop/goooo/printSendMedCfqSyChild.jrxml";
JRXmlWriter.writeReport(report, destinationPath, "UTF-8");
}
}
标签:jasperreports,简单,JRException,jasper,使用,import,net,sf
From: https://www.cnblogs.com/JaxYoun/p/17631950.html