You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ中Spark Submit运行JAR报Class not found及Drools程序JAR运行异常咨询

Troubleshooting Your Drools + Spark Submit Issues

Hey there! Let’s work through your two frustrating problems—these are super common when moving from IDE testing to production/JAR deployments, so I’ve got actionable fixes for each scenario.

1. Drools App Runs in IDE but Fails When Executing the JAR Directly

Most of the time, this boils down to missing dependencies or incorrect resource packaging. Here’s what to check:

  • Missing Drools Dependencies in the JAR
    IDEs automatically pull in all your Maven/Gradle dependencies, but a standard JAR won’t include them by default. You need to build a "fat JAR" (or uber JAR) that bundles all required libraries.

    • For Maven: Use the maven-shade-plugin in your pom.xml. Make sure to configure it to include Drools core libraries like drools-core, drools-compiler, and kie-api. Also, watch for dependency conflicts (e.g., ASM versions used by Drools vs. other libraries)—use the plugin’s relocation feature to rename conflicting packages if needed.
    • For Gradle: Use the shadow plugin, which simplifies fat JAR creation. Add id 'com.github.johnrengelman.shadow' version 'x.x.x' to your plugins block, then run ./gradlew shadowJar to build the bundled JAR.
  • Rule Files/Configuration Not Packaged Correctly
    If your .drl rule files or kmodule.xml (Drools configuration) aren’t in the right place in the JAR, the KieContainer won’t initialize.

    • Ensure .drl files are in the src/main/resources directory (or a subfolder under it). When you build the JAR, check that these files exist under resources/ in the unpacked JAR.
    • Verify kmodule.xml is located at src/main/resources/META-INF/kmodule.xml—this is the default location Drools looks for to load the Kie module.
  • Check the Full Error Stack Trace
    Run the JAR with java -jar your-app.jar and copy the entire error log. Often, the root cause is buried in the stack—like a missing class from a transitive Drools dependency, or a rule file path that works in the IDE but not in the JAR.

2. Class Not Found Error When Running via Spark Submit in IntelliJ

Spark’s classloading model is a bit tricky—here’s why you’re hitting this and how to fix it:

  • Drools Dependencies Aren’t Available to Spark Executors
    When you submit a JAR to Spark, the driver and executors run in separate JVMs. If your JAR doesn’t include Drools dependencies, or Spark isn’t told to pull them in, executors will throw ClassNotFound exceptions.

    • Option 1: Bundle Dependencies in Your Fat JAR
      Use the same fat JAR approach from the first section. Just make sure your Spark dependencies are marked as provided in Maven/Gradle (since Spark clusters already have these libraries) to avoid conflicts.
    • Option 2: Pass Dependencies via Spark Submit Flags
      If you don’t want a fat JAR, use the --jars flag to specify Drools JARs:
      spark-submit --jars drools-core-x.x.x.jar,drools-compiler-x.x.x.jar,kie-api-x.x.x.jar --class com.your.package.MainClass your-app.jar
      
      Or use --packages to pull dependencies directly from Maven Central:
      spark-submit --packages org.drools:drools-core:x.x.x,org.drools:drools-compiler:x.x.x --class com.your.package.MainClass your-app.jar
      
  • Incorrect Main Class Path
    Double-check that the --class parameter in your Spark Submit configuration matches the full qualified name of your main class (e.g., com.example.DroolsSparkApplication). IntelliJ sometimes auto-fills this incorrectly, so verify against your project’s package structure.

  • Classloader Conflicts
    Spark’s default classloader might prioritize its own libraries over your app’s, causing Drools classes to not be found. Try adding these configuration flags to your Spark Submit command:

    --conf spark.driver.userClassPathFirst=true --conf spark.executor.userClassPathFirst=true
    

    Note: This can cause other conflicts, so test it thoroughly before using in production.

Quick Debugging Tips

  • Unpack your JAR with unzip your-app.jar and inspect the BOOT-INF/lib (for Spring Boot) or root directory to confirm Drools classes and rule files are present.
  • In IntelliJ, enable verbose logging for Spark Submit to see exactly which classes are being loaded (or not loaded).

内容的提问来源于stack exchange,提问作者Suhita Goswami

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:15:06