在spark cluster上运行drools-在org.kie.internal.builder.knowledgebuilderfactory.newknowledgebuilder上获取空指针

kg7wmglp  于 2021-05-29  发布在  Spark
关注(0)|答案(1)|浏览(452)

我用口水和Spark来执行一些规则。我已经编写了一个加载.drl文件的方法。并示例化“internalknowledgebase”的对象。下面的代码是在本地模式下工作的,但是当我在集群(emr)中运行时,我得到下面的异常。附加代码和异常堆栈跟踪。

def loadDrl(drlFilePath: String): Option[InternalKnowledgeBase] = {
try {
  val resource = ResourceFactory.newClassPathResource(drlFilePath)
  val kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder() //Exception Occurs
  kbuilder.add(resource, ResourceType.DRL)

  if (kbuilder.hasErrors()) {
    throw new RuntimeException(kbuilder.getErrors().toString())
  }
  val kbase = KnowledgeBaseFactory.newKnowledgeBase()
  kbase.addPackages(kbuilder.getKnowledgePackages())
  Some(kbase)
} catch {
  case e: Exception => { 
    e.printStackTrace()
    None 
    }
 }
}

请查找异常堆栈跟踪。

java.lang.NullPointerException
    at org.kie.internal.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:48)
    at $line27.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw.loadDrl(<pastie>:44)
    at $line33.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw.<init>(<console>:39)
    at $line33.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw.<init>(<console>:44)
    at $line33.$read$$iw$$iw$$iw$$iw$$iw$$iw.<init>(<console>:46)
    at $line33.$read$$iw$$iw$$iw$$iw$$iw.<init>(<console>:48)
    at $line33.$read$$iw$$iw$$iw$$iw.<init>(<console>:50)
    at $line33.$read$$iw$$iw$$iw.<init>(<console>:52)
    at $line33.$read$$iw$$iw.<init>(<console>:54)
    at $line33.$read$$iw.<init>(<console>:56)
    at $line33.$read.<init>(<console>:58)
    at $line33.$read$.<init>(<console>:62)
    at $line33.$read$.<clinit>(<console>)
    at $line33.$eval$.$print$lzycompute(<console>:7)
    at $line33.$eval$.$print(<console>:6)
    at $line33.$eval.$print(<console>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:793)
    at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:1054)
    at scala.tools.nsc.interpreter.IMain$WrappedRequest$$anonfun$loadAndRunReq$1.apply(IMain.scala:645)
    at scala.tools.nsc.interpreter.IMain$WrappedRequest$$anonfun$loadAndRunReq$1.apply(IMain.scala:644)
    at scala.reflect.internal.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:31)
    at scala.reflect.internal.util.AbstractFileClassLoader.asContext(AbstractFileClassLoader.scala:19)
    at scala.tools.nsc.interpreter.IMain$WrappedRequest.loadAndRunReq(IMain.scala:644)
    at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:576)
    at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:572)
    at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:819)
    at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:691)
    at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:404)
    at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:425)
    at org.apache.spark.repl.SparkILoop$$anonfun$process$1.apply$mcZ$sp(SparkILoop.scala:285)
    at org.apache.spark.repl.SparkILoop.runClosure(SparkILoop.scala:159)
    at org.apache.spark.repl.SparkILoop.process(SparkILoop.scala:182)
    at org.apache.spark.repl.Main$.doMain(Main.scala:78)
    at org.apache.spark.repl.Main$.main(Main.scala:58)
    at org.apache.spark.repl.Main.main(Main.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
    at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:849)
    at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:167)
    at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:195)
    at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:86)
    at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:924)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:933)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

谢谢你的帮助!谢谢。

0md85ypi

0md85ypi1#

不久前我也遇到过类似的问题。我的工作是用遮阳板做一个jar。找到其中一个问题后解决(不记得有一个问题):
drools 7.4.1.services.factory.get()返回null
如何在storm拓扑中使用drools
必须将此转换器添加到pom.xml中

<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
    <resource>META-INF/kie.conf</resource>
</transformer>

相关问题