title: How to integrate KIE Workbench 6.1.0.Final (Drools Guvnor) Project with Java Application
body: <p>I am using KIE Workbench 6.1.0.Final and my Eclipse project where I am trying to execute rules is also 6.1.0 Runtime enabled.</p>
  
  <p>I like to know how I can execute/load rules created using Drools Guvnor, from my java application. Before posting this question, I have looked at the following similar questions and tried the given approaches but none of them worked for me.</p>
  
  <p><a href="https://stackoverflow.com/questions/25129499/integrating-drool-6-work-bench-with-java-application">Integrating Drool 6 work bench with Java Application</a></p>
  
  <p><a href="https://stackoverflow.com/questions/20995133/why-does-loading-drools-6-kie-jar-into-code-fail">why does loading Drools 6 KIE JAR into code fail?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/21186570/loading-drools-kie-workbench-artifacts-directly-from-the-repository">Loading Drools/KIE Workbench artifacts directly from the repository</a></p>
  
  <p><a href="https://stackoverflow.com/questions/27487996/kie-workbench-integration-responds-with-401">KIE Workbench Integration Responds with 401</a></p>
  
  <p>I have followed the steps given here <a href="http://docs.jboss.org/drools/release/6.0.1.Final/drools-docs/html_single/#wb.Workbench" rel="nofollow noreferrer">click this</a>  to create a project and defined the rule. I am able to build and deploy the rules. I have tried the following code to load the projects but all fails with different exception. Pls note that I am able to access the workbench jar from the browser.</p>
  
  <p>Approach 1. </p>
  
  <pre><code>public void load1(){
      KieServices kieServices = KieServices.Factory.get();
      ReleaseId releaseId = kieServices.newReleaseId( "com.example.rule", "RuleProject", "1.0" );
      KieContainer kContainer = kieServices.newKieContainer( releaseId );
      KieBaseConfiguration kieBaseConf = kieServices.newKieBaseConfiguration();
      kieBaseConf.setOption( EventProcessingOption.STREAM );
      KieBase kBase = kContainer.newKieBase(kieBaseConf);
      for ( KiePackage a : kBase.getKiePackages()) {
          for (Rule r : a.getRules()) {
              System.out.println("KiePackage {} Rule {}"+ new Object[]{a.getName()+"-"+ r.getName()});
          }
      }
  }
  </code></pre>
  
  <p>Exception</p>
  
  <p>java.lang.RuntimeException: Cannot find KieModule: com.example.rule:RuleProject:1.0
      at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:99)</p>
  
  <p>Approach 2.</p>
  
  <pre><code>public void load2(){            
      String url = "http://example.com/drools/maven2/com/example/rule/RuleProject/1.0/RuleProject-1.0.jar";
      ReleaseIdImpl releaseId = new ReleaseIdImpl("com.example.rule", "RuleProject", "1.0");
      KieServices kieServices = KieServices.Factory.get();
      kieServices.getResources().newUrlResource(url);
      KieContainer kieContainer = kieServices.newKieContainer(releaseId);     
      // check every 5 seconds if there is a new version at the URL
      KieScanner kieScanner = kieServices.newKieScanner(kieContainer);
      kieScanner.start(5000L);
      // alternatively:
      // kieScanner.scanNow();
      Scanner scanner = new Scanner(System.in);
      while (true) {
          //runRule(kieContainer);
          System.out.println("Press enter in order to run the test again....");
          scanner.nextLine();
      }
  }
  </code></pre>
  
  <p>Exception </p>
  
  <p>java.lang.RuntimeException: Cannot find KieModule: com.example.rule:RuleProject:1.0
      at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:99)</p>
  
  <p>Approach 3. </p>
  
  <pre><code>public void load3() throws IOException{         
      String url = "http://example.com/drools/maven2/com/example/rule/RuleProject/1.0/RuleProject-1.0.jar";
      KieServices ks = KieServices.Factory.get();
      KieRepository kr = ks.getRepository();
      UrlResource urlResource = (UrlResource) ks.getResources()
              .newUrlResource(url);
      urlResource.setUsername("admin");
      urlResource.setPassword("password");
      urlResource.setBasicAuthentication("enabled");
      InputStream is = urlResource.getInputStream();
      KieModule kModule = kr.addKieModule(ks.getResources()
              .newInputStreamResource(is));
      KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());
  
      kContainer.newStatelessKieSession();        
  
  }
  </code></pre>
  
  <p>Exception</p>
  
  <pre><code>java.io.IOException: Server returned HTTP response code: 401 for URL: http://example.com/drools/maven2/com/example/rule/RuleProject/1.0/RuleProject-1.0.jar
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
      at org.drools.core.io.impl.UrlResource.grabStream(UrlResource.java:257)
      at org.drools.core.io.impl.UrlResource.getInputStream(UrlResource.java:174)
  </code></pre>
  
  <p>Here is my workbench jar pom.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;com.example.rule&lt;/groupId&gt;
    &lt;artifactId&gt;RuleProject&lt;/artifactId&gt;
    &lt;version&gt;1.0&lt;/version&gt;
    &lt;packaging&gt;kjar&lt;/packaging&gt;
    &lt;name&gt;RuleProject&lt;/name&gt;
    &lt;repositories&gt;
      &lt;repository&gt;
        &lt;id&gt;guvnor-m2-repo&lt;/id&gt;
        &lt;name&gt;Guvnor M2 Repo&lt;/name&gt;
        &lt;url&gt;http://localhost:8080/drools/maven2/&lt;/url&gt;
      &lt;/repository&gt;
    &lt;/repositories&gt;
    &lt;build&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.kie&lt;/groupId&gt;
          &lt;artifactId&gt;kie-maven-plugin&lt;/artifactId&gt;
          &lt;version&gt;6.1.0.Final&lt;/version&gt;
          &lt;extensions&gt;true&lt;/extensions&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Here is my java application pom.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;xcp.drool&lt;/groupId&gt;
    &lt;artifactId&gt;xcpdrool&lt;/artifactId&gt;
    &lt;version&gt;1&lt;/version&gt;
    &lt;repositories&gt;
      &lt;repository&gt;
        &lt;releases&gt;
          &lt;enabled&gt;true&lt;/enabled&gt;
          &lt;updatePolicy&gt;always&lt;/updatePolicy&gt;
        &lt;/releases&gt;
        &lt;id&gt;guvnor-m2-repo&lt;/id&gt;
        &lt;name&gt;Guvnor M2 Repo&lt;/name&gt;
        &lt;url&gt;http://localhost:8080/drools/maven2/&lt;/url&gt;
      &lt;/repository&gt;
      &lt;repository&gt;
        &lt;snapshots&gt;
          &lt;enabled&gt;false&lt;/enabled&gt;
        &lt;/snapshots&gt;
        &lt;id&gt;central&lt;/id&gt;
        &lt;name&gt;Central Repository&lt;/name&gt;
        &lt;url&gt;http://repo.maven.apache.org/maven2&lt;/url&gt;
      &lt;/repository&gt;
    &lt;/repositories&gt;
    &lt;pluginRepositories&gt;
      &lt;pluginRepository&gt;
        &lt;releases&gt;
          &lt;updatePolicy&gt;never&lt;/updatePolicy&gt;
        &lt;/releases&gt;
        &lt;snapshots&gt;
          &lt;enabled&gt;false&lt;/enabled&gt;
        &lt;/snapshots&gt;
        &lt;id&gt;central&lt;/id&gt;
        &lt;name&gt;Central Repository&lt;/name&gt;
        &lt;url&gt;http://repo.maven.apache.org/maven2&lt;/url&gt;
      &lt;/pluginRepository&gt;
    &lt;/pluginRepositories&gt;
    &lt;build&gt;
      &lt;sourceDirectory&gt;C:\p4_xb\xCP-Drool\xCPDrool1\src\main\java&lt;/sourceDirectory&gt;
      &lt;scriptSourceDirectory&gt;C:\p4_xb\xCP-Drool\xCPDrool1\src\main\scripts&lt;/scriptSourceDirectory&gt;
      &lt;testSourceDirectory&gt;C:\p4_xb\xCP-Drool\xCPDrool1\src\test\java&lt;/testSourceDirectory&gt;
      &lt;outputDirectory&gt;C:\p4_xb\xCP-Drool\xCPDrool1\target\classes&lt;/outputDirectory&gt;
      &lt;testOutputDirectory&gt;C:\p4_xb\xCP-Drool\xCPDrool1\target\test-classes&lt;/testOutputDirectory&gt;
      &lt;resources&gt;
        &lt;resource&gt;
          &lt;directory&gt;C:\p4_xb\xCP-Drool\xCPDrool1\src\main\resources&lt;/directory&gt;
        &lt;/resource&gt;
      &lt;/resources&gt;
      &lt;testResources&gt;
        &lt;testResource&gt;
          &lt;directory&gt;C:\p4_xb\xCP-Drool\xCPDrool1\src\test\resources&lt;/directory&gt;
        &lt;/testResource&gt;
      &lt;/testResources&gt;
      &lt;directory&gt;C:\p4_xb\xCP-Drool\xCPDrool1\target&lt;/directory&gt;
      &lt;finalName&gt;xcpdrool-1&lt;/finalName&gt;
      &lt;pluginManagement&gt;
        &lt;plugins&gt;
          &lt;plugin&gt;
            &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
            &lt;version&gt;1.3&lt;/version&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
            &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.2-beta-5&lt;/version&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
            &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.1&lt;/version&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
            &lt;artifactId&gt;maven-release-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.0&lt;/version&gt;
          &lt;/plugin&gt;
        &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-clean-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.4.1&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-clean&lt;/id&gt;
              &lt;phase&gt;clean&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;clean&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-install-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.3.1&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-install&lt;/id&gt;
              &lt;phase&gt;install&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;install&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.5&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-resources&lt;/id&gt;
              &lt;phase&gt;process-resources&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;resources&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
            &lt;execution&gt;
              &lt;id&gt;default-testResources&lt;/id&gt;
              &lt;phase&gt;process-test-resources&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;testResources&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.10&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-test&lt;/id&gt;
              &lt;phase&gt;test&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;test&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.3.2&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-testCompile&lt;/id&gt;
              &lt;phase&gt;test-compile&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;testCompile&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
            &lt;execution&gt;
              &lt;id&gt;default-compile&lt;/id&gt;
              &lt;phase&gt;compile&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;compile&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.3.2&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-jar&lt;/id&gt;
              &lt;phase&gt;package&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;jar&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-deploy-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.7&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-deploy&lt;/id&gt;
              &lt;phase&gt;deploy&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;deploy&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-site-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.0&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-site&lt;/id&gt;
              &lt;phase&gt;site&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;site&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;configuration&gt;
                &lt;outputDirectory&gt;C:\p4_xb\xCP-Drool\xCPDrool1\target\site&lt;/outputDirectory&gt;
                &lt;reportPlugins&gt;
                  &lt;reportPlugin&gt;
                    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                    &lt;artifactId&gt;maven-project-info-reports-plugin&lt;/artifactId&gt;
                  &lt;/reportPlugin&gt;
                &lt;/reportPlugins&gt;
              &lt;/configuration&gt;
            &lt;/execution&gt;
            &lt;execution&gt;
              &lt;id&gt;default-deploy&lt;/id&gt;
              &lt;phase&gt;site-deploy&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;deploy&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;configuration&gt;
                &lt;outputDirectory&gt;C:\p4_xb\xCP-Drool\xCPDrool1\target\site&lt;/outputDirectory&gt;
                &lt;reportPlugins&gt;
                  &lt;reportPlugin&gt;
                    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                    &lt;artifactId&gt;maven-project-info-reports-plugin&lt;/artifactId&gt;
                  &lt;/reportPlugin&gt;
                &lt;/reportPlugins&gt;
              &lt;/configuration&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
          &lt;configuration&gt;
            &lt;outputDirectory&gt;C:\p4_xb\xCP-Drool\xCPDrool1\target\site&lt;/outputDirectory&gt;
            &lt;reportPlugins&gt;
              &lt;reportPlugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-project-info-reports-plugin&lt;/artifactId&gt;
              &lt;/reportPlugin&gt;
            &lt;/reportPlugins&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
    &lt;reporting&gt;
      &lt;outputDirectory&gt;C:\p4_xb\xCP-Drool\xCPDrool1\target\site&lt;/outputDirectory&gt;
    &lt;/reporting&gt;
    &lt;profiles&gt;
      &lt;profile&gt;
        &lt;activation&gt;
          &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
        &lt;/activation&gt;
        &lt;repositories&gt;
          &lt;repository&gt;
            &lt;releases&gt;
              &lt;enabled&gt;true&lt;/enabled&gt;
              &lt;updatePolicy&gt;always&lt;/updatePolicy&gt;
            &lt;/releases&gt;
            &lt;id&gt;guvnor-m2-repo&lt;/id&gt;
            &lt;name&gt;Guvnor M2 Repo&lt;/name&gt;
            &lt;url&gt;http://localhost:8080/drools/maven2/&lt;/url&gt;
          &lt;/repository&gt;
        &lt;/repositories&gt;
      &lt;/profile&gt;
    &lt;/profiles&gt;
  &lt;/project&gt;
  </code></pre>