我使用xdocreport生成一個文件。在它的IDE工作正常,但一旦我測試我的程序作爲一個運行的JAR,不再被生成的文件,而不是我得到的錯誤,當我嘗試以按給定的tutoriel運行的JARXdocreport在IDE中生成文件但不是從jar中生成文件
fr.opensagres.xdocreport.core.XDocReportException: Null template engine. Set template engine with IXDocReport#setTemplateEngine.
同樣的事情發生the xdocreport projet
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();
}
}
}
的錯誤似乎在行occure:
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in,TemplateEngineKind.Velocity);
我如何能解決這個問題(至少教程)任何想法?我曾嘗試將該文件放在許多不同的路徑中,但它仍然無法通過可運行的jar找到。
謝謝
您的問題是因爲您的可運行JAR中沒有Velocity和/或它們的依賴關係。 – Angelo