gpt4 book ai didi

java - 如何修复 "JRException: Error compiling report java source files"错误?

转载 作者:行者123 更新时间:2023-12-01 18:12:10 27 4
gpt4 key购买 nike

搜索后,我发现可以将 XML 作为输入并将其设置为 PDF,但我收到此错误。任何帮助将不胜感激。

@Service
public class PDFGenerationDemo implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public static final String RESOURCES_DIR;
public static final String OUTPUT_DIR;

static {
RESOURCES_DIR = "src//main//resources//";
OUTPUT_DIR = "src//main//resources//output//";
}

public void makeHTML() throws IOException, TemplateException, JRException {
File file = ResourceUtils.getFile("classpath:jasper.jrxml");
JasperReport jReport=JasperCompileManager.compileReport(file.getAbsolutePath());
Map<String, Object> params = new HashMap<String, Object>();
Document document =
JRXmlUtils.parse(JRLoader.getLocationInputStream(RESOURCES_DIR+"sample.xml"));
params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
params.put(JRXPathQueryExecuterFactory.XML_DATE_PATTERN, "yyyy-MM-dd");
params.put(JRXPathQueryExecuterFactory.XML_NUMBER_PATTERN, "#,##0.##");
params.put(JRXPathQueryExecuterFactory.XML_LOCALE, Locale.ENGLISH);
params.put(JRParameter.REPORT_LOCALE, Locale.US);
JasperPrint jPrint = JasperFillManager.fillReport(jReport, params);
JasperExportManager.exportReportToPdfFile(jPrint,OUTPUT_DIR+"CustomersReport.pdf");
}
}

错误

2020-02-28 14:39:44 [http-nio-9005-exec-2] DEBUG o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolving exception from handler [public void com.imoveinvest.propertyuploader.controller.SaveOrValidateValuationReport.htmlCall() throws java.io.IOException,freemarker.template.TemplateException,net.sf.jasperreports.engine.JRException]: net.sf.jasperreports.engine.JRException: Error compiling report java source files: D:\SanjayS\ImoveHome\property-uploade-service\Blank_A4_1582880983002_121813.java .
2020-02-28 14:39:44 [http-nio-9005-exec-2] DEBUG o.s.w.s.m.a.ResponseStatusExceptionResolver - Resolving exception from handler [public void com.imoveinvest.propertyuploader.controller.SaveOrValidateValuationReport.htmlCall() throws java.io.IOException,freemarker.template.TemplateException,net.sf.jasperreports.engine.JRException]: net.sf.jasperreports.engine.JRException: Error compiling report java source files: D:\SanjayS\ImoveHome\property-uploade-service\Blank_A4_1582880983002_121813.java .
2020-02-28 14:39:44 [http-nio-9005-exec-2] DEBUG o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolving exception from handler [public void com.imoveinvest.propertyuploader.controller.SaveOrValidateValuationReport.htmlCall() throws java.io.IOException,freemarker.template.TemplateException,net.sf.jasperreports.engine.JRException]: net.sf.jasperreports.engine.JRException: Error compiling report java source files: D:\SanjayS\ImoveHome\property-uploade-service\Blank_A4_1582880983002_121813.java .
2020-02-28 14:39:44 [http-nio-9005-exec-2] DEBUG o.s.web.servlet.DispatcherServlet - Could not complete request
net.sf.jasperreports.engine.JRException: Error compiling report java source files: D:\SanjayS\ImoveHome\property-uploade-service\Blank_A4_1582880983002_121813.java .
Caused by: java.io.IOException: Cannot run program "javac": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at net.sf.jasperreports.engine.design.JRJavacCompiler.compileClasses(JRJavacCompiler.java:63)
... 49 common frames omitted

I have been struggling a lot with this please help.

最佳答案

当您打开命令行 shell 并输入“javac”时会发生什么?是否失败并提示找不到程序“javac”?

看起来 jasper 报告正在生成 Java 代码,然后尝试编译它(javac 是 Java 编译器),但它找不到编译器。这可能是因为它尚未安装,或者可能是它不在您的“路径”上。详细信息将取决于您使用的操作系统。但希望这能提供有关问题所在的线索并帮助您解决问题。

(实际上,仔细查看诊断结果会告诉我您使用的是 Windows,这意味着我无法提供比这更多的详细信息。)

关于java - 如何修复 "JRException: Error compiling report java source files"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60448702/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com