title: newKieSession() returns null when project is exported to JAR
body: <p>Very confusing problem here. I see behavior which differs between running the project in Eclipse and running the project as an exported JAR. When the project runs in Eclipse, it runs fine. When it runs as a JAR, it crashes. The crash results from the <code>newKieSession</code> method. </p>
  
  <p>Here is the code block:</p>
  
  <pre><code>KieServices ks = KieServices.Factory.get();
  KieContainer kContainer = ks.getKieClasspathContainer();
  KieSession kSession = kContainer.newKieSession("ksession-rules");
  </code></pre>
  
  <p>When run from Eclipse, it works fine. When I export the JAR and run it, the <code>kSession</code> is <code>null</code>. Later on I access the <code>kSession</code> object which causes a <code>NullPointerException</code>. I have tried breaking immediately following the above line just to confirm I'm not somehow nullifying it later. I can confirm that <code>ksession</code> is <code>null</code> immediately following that call to <code>newKieSession()</code>.</p>
  
  <p>Does anyone have any idea why the behavior would differ? I have confirmed I am exporting using the exact same run configuration. When I export, I have tried both <code>"Extract required libraries into generated JAR"</code> as well as <code>"Package required libraries into generated jar"</code>. The error happens with both.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Noticed another error message in the deluge of information returned at the console before the exception.</p>
  
  <pre><code>[main] ERROR org.drools.compiler.kie.builder.impl.KieContainerImpl - Unknown KieSession name: ksession-rules
  </code></pre>
  
  <p>I don't get this when I run via Eclipse.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Attached is the structure of the project in Eclipse. I have expanded the resource folder since it seems the most relevant to the situation.</p>
  
  <p><a href="https://i.stack.imgur.com/IWCi3.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IWCi3.jpg" alt="enter image description here"></a></p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>The jar file contains a resources folder with the same structure as the eclipse screenshot. So, at the root of the jar, we can find the following:</p>
  
  <pre><code>/resources/rules/*.drl
  /resources/META-INF/kmodule.xml
  </code></pre>
  
  <p>Content of kmodule.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"&gt;
      &lt;kbase name="rules" packages="com.company.project"&gt;
          &lt;ksession name="ksession-rules"/&gt;
      &lt;/kbase&gt;
  &lt;/kmodule&gt;
  </code></pre>
  
  <p>I also tried the following kmodule with the same results:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"&gt;
      &lt;kbase name="rules" packages="rules"&gt;
          &lt;ksession name="ksession-rules"/&gt;
      &lt;/kbase&gt;
  &lt;/kmodule&gt;
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The root of the jar appears to have a second META-INF folder. So the jar has the following:</p>
  
  <pre><code>/META-INF
  /resources/rules/*.drl
  /resources/META-INF/kmodule.xml
  </code></pre>
  
  <p>I tried building a sample drools program, and I noted that the <code>kmodule.xml</code> file ends up at <code>/META-INF/kmodule.xml</code> when sample drools program is exported to jar. I have no idea why the behavior of my jar export is different. The paths in the project are exactly the same and I am exporting it using exactly the same process.</p>