Drools的决策表xls文件转drl文件所依赖的poi版本

1.最近的项目中使用到了Drools作为规则引擎,今天在开发决策表的导入功能时(xls文件转drl),网上提供的简要例子始终通不过,报找不到类的错误:

示例如下:

try {
    ruleTableConvertDRL("D:\\calculation.xls");
} catch (IOException e) {
    e.printStackTrace();
}

/**
 * 将xls决策表解析为普通规则文件
 * @throws IOException
 */
public File ruleTableConvertDRL(String ruleTablePath) throws IOException {
    SpreadsheetCompiler compiler = new SpreadsheetCompiler();
    File inFile = new File(ruleTablePath);
    File outFile = new File("D:\\outFile.txt");
    InputStream xlsStream = null;
    OutputStream fos = null;
    OutputStreamWriter osw = null;
    BufferedWriter out = null;
    try {
        xlsStream = new FileInputStream(inFile);
        fos = new FileOutputStream(outFile);
        osw = new OutputStreamWriter(fos);
        out = new BufferedWriter(osw);
        String strRule = compiler.compile(xlsStream, InputType.XLS);
        out.write(strRule);
        out.flush();
        System.out.println("\n" + strRule);
    } catch (IOException e) {
        throw new IOException("没找到文件或写入文件错误");
    }finally{
        xlsStream.close();
        fos.close();
        osw.close();
        out.close();
    }
    return outFile;
}

 
 

2.报错如下:

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Workbook.close()V at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:982) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

Caused by: java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Workbook.close()V at org.drools.decisiontable.parser.xls.ExcelParser.parseWorkbook(ExcelParser.java:124) at org.drools.decisiontable.parser.xls.ExcelParser.parseFile(ExcelParser.java:83) at org.drools.decisiontable.SpreadsheetCompiler.compile(SpreadsheetCompiler.java:103) at org.drools.decisiontable.SpreadsheetCompiler.compile(SpreadsheetCompiler.java:76)

3.首先我的第一反应就是应该是jar包冲突,我当时用的drools版本是6.4,poi是3.9:

4.后来经过多次尝试,选择drools为7.0版本,poi为3.15版本时,测试通过,后台可以正常输出决策表内容

5.drools和poi版本如下:

<dependency>
   <groupId>org.kie</groupId>
   <artifactId>kie-api</artifactId>
   <version>7.0.0.Final</version>
</dependency>
<dependency>
   <groupId>org.drools</groupId>
   <artifactId>drools-core</artifactId>
   <version>7.0.0.Final</version>
</dependency>
<dependency>
   <groupId>org.drools</groupId>
   <artifactId>drools-compiler</artifactId>
   <version>7.0.0.Final</version>
</dependency>
<dependency>
   <groupId>org.drools</groupId>
   <artifactId>drools-decisiontables</artifactId>
   <version>7.0.0.Final</version>
</dependency>
<dependency>
   <groupId>org.drools</groupId>
   <artifactId>drools-templates</artifactId>
   <version>7.0.0.Final</version>
</dependency>
<!-- apahce poi -->
<dependency>
   <groupId>org.apache.poi</groupId>
   <artifactId>poi</artifactId>
   <version>3.15</version>
</dependency>
<dependency>
   <groupId>org.apache.poi</groupId>
   <artifactId>poi-ooxml</artifactId>
   <version>3.15</version>
</dependency>
<dependency>
   <groupId>org.apache.poi</groupId>
   <artifactId>poi-ooxml-schemas</artifactId>
   <version>3.15</version>
</dependency>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值