我使用 xdocreport 生成一个 word 文件。在 IDE 中它工作正常,但是一旦我将我的程序测试为可运行的 jar,就不再生成该文件,而是出现错误
fr.opensagres.xdocreport.core.XDocReportException: Null template engine. Set template engine with IXDocReport#setTemplateEngine.
当我使用xdocreport projet 中给出的教程尝试一个可运行的 jar 时,也会发生同样的事情
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import fr.opensagres.xdocreport.core.XDocReportException;
import fr.opensagres.xdocreport.document.IXDocReport;
import fr.opensagres.xdocreport.document.registry.XDocReportRegistry;
import fr.opensagres.xdocreport.template.IContext;
import fr.opensagres.xdocreport.template.TemplateEngineKind;
public class testing {
public static void main(String[] args) {
try {
// 1) Load ODT file by filling Velocity template engine and cache it to the registry
InputStream in = testing.class.getResourceAsStream("DocxProjectWithVelocity.docx");
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in,TemplateEngineKind.Velocity);
// 2) Create context Java model
IContext context = report.createContext();
Project project = new Project("XDocReport");
context.put("project", project);
// 3) Generate report by merging Java model with the ODT
OutputStream out = new FileOutputStream(new File("DocxProjectWithVelocity_out.docx"));
report.process(context, out);
} catch (IOException e) {
e.printStackTrace();
} catch (XDocReportException e) {
e.printStackTrace();
}
}
}
该错误似乎发生在该行:
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in,TemplateEngineKind.Velocity);
关于如何克服这个问题的任何想法(至少在本教程中)?我尝试将文件放在许多不同的路径中,但可运行的 jar 仍然找不到它。
谢谢你