0 Replies Latest reply on Dec 18, 2013 5:55 AM by Kannan g krishnan

    Failed run the business rule task

    Kannan g krishnan Newbie

      Hi i am trying to include the business rule task in my project. I am trying with an example process which is showing some errors

       

      The steps i followed:

      1. i created a java project in my eclipse. There is a class named Person. which consists of a variable name and the getter and setter methods for the variable.

      2. converted the project into a .jar file.

      3. created new package and category in the drools. Uploaded new POJO model jar and created new rule like this.

       

      rule "hellowname"
      ruleflow-group "nametest"
      dialect "mvel"
      when
      Person( $name : name)
      then
      System.out.print("Hello "+$name);

      end

       

      4. Then i have created a workllow with this business rule which contains

          a. Start node

          b. Business task

          c. End node

          i also mentioned the Ruleflow group name in the properties.

      Build the package and created the snapshot.

      5. Created a jbpm project in the eclipse and imported this workflow file to the project.

      6. Created a file named demochanges.xml

       

      which contains the code:

      <change-set xmlns='http://drools.org/drools-5.0/change-set' xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'

       

      xs:schemaLocation='http://drools.org/drools-5.0/change-set http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd' >

       

      <add>

          <resource source='http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/com.sample/LATEST' type='PKG' basicAuthentication="enabled" username="admin" password="admin"/>

      </add>

       

      </change-set>

       

      Modified the ProcessMain.java as follows:

       

      package com.sample;

       

      import org.drools.KnowledgeBase;

      import org.drools.builder.KnowledgeBuilder;

      import org.drools.builder.KnowledgeBuilderFactory;

      import org.drools.builder.ResourceType;

      import org.drools.definition.type.FactType;

      import org.drools.io.ResourceFactory;

      import org.drools.runtime.StatefulKnowledgeSession;

       

      /**

      * This is a sample file to launch a process.

      */

      public class ProcessMain {

       

          public static final void main(String[] args) throws Exception {

             

              try{

              // load up the knowledge base

              KnowledgeBase kbase = readKnowledgeBase();

              StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

              System.out.println("here");

              FactType personType=kbase.getFactType("com.sample", "Person");

              System.out.println("here");

              Object kannan=personType.newInstance();

              personType.set(kannan,"name","kannan");

              ksession.insert(kannan);

              ksession.startProcess("Nametest");

              ksession.fireAllRules();

              }catch(Exception e){

                  System.out.println(e);

                  e.printStackTrace();}

          }

       

          private static KnowledgeBase readKnowledgeBase() throws Exception {

              KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

              try{

              kbuilder.add(ResourceFactory.newClassPathResource("demochangeset.xml"), ResourceType.CHANGE_SET);

              }catch(Exception e){System.out.println("i am here "+e);}

              return kbuilder.newKnowledgeBase();

          }

         

      }

       

       

      Now my problem is when i try to run the main method i got a ClassNotFound exception like this.

       

      java.lang.RuntimeException: java.lang.ClassNotFoundException: Unable to load class: com.sample.Person

      java.lang.RuntimeException: java.lang.ClassNotFoundException: Unable to load class: com.sample.Person

          at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:726)

          at org.drools.compiler.PackageBuilder.addPackageFromChangeSet(PackageBuilder.java:807)

          at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:715)

          at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)

          at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)

          at com.sample.ProcessMain.readKnowledgeBase(ProcessMain.java:40)

          at com.sample.ProcessMain.main(ProcessMain.java:20)

      Caused by: java.lang.ClassNotFoundException: Unable to load class: com.sample.Person

          at org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:92)

          at java.lang.ClassLoader.loadClass(Unknown Source)

          at java.lang.Class.forName0(Native Method)

          at java.lang.Class.forName(Unknown Source)

          at org.drools.common.DroolsObjectInputStream.resolveClass(DroolsObjectInputStream.java:85)

          at org.drools.common.DroolsObjectInputStream.resolveClass(DroolsObjectInputStream.java:97)

          at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)

          at java.io.ObjectInputStream.readClassDesc(Unknown Source)

          at java.io.ObjectInputStream.readClass(Unknown Source)

          at java.io.ObjectInputStream.readObject0(Unknown Source)

          at java.io.ObjectInputStream.readObject(Unknown Source)

          at java.util.HashMap.readObject(Unknown Source)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)

          at java.io.ObjectInputStream.readSerialData(Unknown Source)

          at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

          at java.io.ObjectInputStream.readObject0(Unknown Source)

          at java.io.ObjectInputStream.readObject(Unknown Source)

          at org.drools.rule.MVELDialectRuntimeData.readExternal(MVELDialectRuntimeData.java:87)

          at java.io.ObjectInputStream.readExternalData(Unknown Source)

          at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

          at java.io.ObjectInputStream.readObject0(Unknown Source)

          at java.io.ObjectInputStream.readObject(Unknown Source)

          at java.util.HashMap.readObject(Unknown Source)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)

          at java.io.ObjectInputStream.readSerialData(Unknown Source)

          at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

          at java.io.ObjectInputStream.readObject0(Unknown Source)

          at java.io.ObjectInputStream.readObject(Unknown Source)

          at org.drools.rule.DialectRuntimeRegistry.readExternal(DialectRuntimeRegistry.java:58)

          at java.io.ObjectInputStream.readExternalData(Unknown Source)

          at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

          at java.io.ObjectInputStream.readObject0(Unknown Source)

          at java.io.ObjectInputStream.readObject(Unknown Source)

          at org.drools.rule.Package.readExternal(Package.java:208)

          at java.io.ObjectInputStream.readExternalData(Unknown Source)

          at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

          at java.io.ObjectInputStream.readObject0(Unknown Source)

          at java.io.ObjectInputStream.readArray(Unknown Source)

          at java.io.ObjectInputStream.readObject0(Unknown Source)

          at java.io.ObjectInputStream.readObject(Unknown Source)

          at org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:205)

          at org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:189)

          at org.drools.compiler.PackageBuilder.addPackageFromInputStream(PackageBuilder.java:821)

          at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:713)

          ... 6 more

       

       

      Can somebody help me what i am missing?? why it cannot find the class????

       

      Thanks and regards

      Kannan