xdocreport を使用してワード ファイルを生成します。IDE では正常に動作しますが、プログラムを実行可能な jar としてテストすると、ファイルが生成されなくなり、代わりにエラーが発生します。
fr.opensagres.xdocreport.core.XDocReportException: Null template engine. Set template engine with IXDocReport#setTemplateEngine.
xdocreport プロジェクトで指定されたチュートリアルで実行可能な 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 ではまだ見つかりません。
ありがとうございました