下面這段是FR7.1版本二次開發把模板導出成pdf文件的語句:
public static void main(String[] args) throws Exception{
String envpath = "c:\\Program Files\\FineReport_7.1\\WebReport\\WEB-INF";
FRContext.setCurrentEnv(new LocalEnv(envpath));
ModuleContext.startModule(EngineModule.class.getName());
String cptname = "00.cpt";
WorkBook workbook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(FRContext.getCurrentEnv(), cptname);
OutputStream outputStream = new FileOutputStream(new File("c:\\TxtExport.txt"));
TextExporter TxtExport = new TextExporter();
Map parameterMap = new HashMap();
parameterMap.put("p1", "sdf");
TxtExport.export(outputStream, workbook.execute(parameterMap, ActorFactory.getActor("page")));
outputStream.close();
ModuleContext.stopModules();
}
思路很簡單,啓動FR的工程模塊,加載解析模板導出到pdf,最後調用ModuleContext.stopModules()關閉模塊。
問題是執行到最後發現主進程並沒有退出。
這是因爲有子線程還在執行。這個子線程是填報模塊(WriteModule)的excel批量導入服務(ExcelSubmitService)中定義的一個定時任務。stopModules並沒有關閉掉這個定時任務的線程。所以需要在最後加上一句:new WriteModule().stop()。