Drools 资源既没有源路径,也没有目标路径。无法将其添加到捆绑包中

Drools 资源既没有源路径,也没有目标路径。无法将其添加到捆绑包中,drools,kie,Drools,Kie,我正在尝试使用kie api 6读取带有规则的.xlsx文件。 但是我得到了这个例外 java.lang.RuntimeException: Resource does not have neither a source nor a target path. Impossible to add it to the bundle. P lease set either the source or target name of the resource before adding it.null

我正在尝试使用
kie api 6
读取带有规则的
.xlsx
文件。 但是我得到了这个例外

java.lang.RuntimeException: Resource does not have neither a source nor a target path. Impossible to add it to the bundle. P
lease set either the source or target name of the resource before adding it.null
        at org.drools.compiler.kie.builder.impl.KieFileSystemImpl.write(KieFileSystemImpl.java:83)
        at com.project.watch.validator.RuleValidator.isValidRuleKieNew(RuleValidator.java:71)
        at com.project.watch.validator.RuleValidator.isValidRule(RuleValidator.java:37)
        at com.project.watch.core.WatchDir$ValidateFileRunnable.run(WatchDir.java:177)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:
178)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
代码如下所示

try { 
        KieServices ks = KieServices.Factory.get();
        KieFileSystem kfs = ks.newKieFileSystem();
        kfs.write(ks.getResources().newInputStreamResource(Files.newInputStream(p, StandardOpenOption.READ)));
        KieBuilder kb = ks.newKieBuilder(kfs);
        if (kb.getResults().getMessages(Level.ERROR).size() != 0) {
            logger.lifecycle("Invalid file: {}.", kb.getResults().getMessages());
            return false;
        }
    } catch (Exception e) {
        logger.lifecycle("UNEXPECTED ERROR DURING VALIDATION -------------- ", e);
        return false;
    }
    logger.lifecycle("Valid file: {}.", p);
    return true;
}
它在kfs上失败。顺便说一句,写下

我还通过在控制台中显示来检查文件的路径

Attempt to process rule file: D:\PROJECT_FOLDER\project\src\testInteg\resources\rules\rule.xlsx
这是一条正确的道路。
有什么问题吗?我使用的是
6.3最终版。

我建议使用此咒语,假设您的
字符串p
包含路径名,如图所示:

FileInputStream fis = new FileInputStream( p );
kfs.write( "src/main/resources/rule.xslx",
           kieServices.getResources().newInputStreamResource( fis ) );

对于
文件系统
写入
还有一些其他形式,但我发现这很容易使用。您可以使用Java的API作为路径名,从
p
派生
rule.xslx

的确如此。我是这样解决的。但是在这种情况下,base
write
的目的是什么?资源可能有一个与其相关联的路径名-那么简单的
write(Resource Resource)
就足够了。(无可否认,我从来没有尝试去探究这个问题,文档是,嗯,是,现在它在哪里,嗯…)