[rules-users] Very basic running of drools 5, basic setup and quickstart

Greg Barton greg_barton at yahoo.com
Sun Apr 25 19:14:32 EDT 2010


The best documentation to read would be the maven docs:

http://maven.apache.org/

But if you drop the attached pom.xml into a project created by drools' eclipse plugin it'll work fine.  type "mvn clean install" from the project home directory and it'll build. (After downloading half the known universe...)

--- On Thu, 4/22/10, Berlin Brown <berlin.brown at gmail.com> wrote:

From: Berlin Brown <berlin.brown at gmail.com>
Subject: Re: [rules-users] Very basic running of drools 5, basic setup and  quickstart
To: "Rules Users List" <rules-users at lists.jboss.org>
Date: Thursday, April 22, 2010, 5:11 PM

Is there documentation on how to do this, including a full example.  I saw the pom file, but still don't know the run/compile targets?

2010/4/22 Greg Barton <greg_barton at yahoo.com>


Have you ever thought of using maven?  Your problem is no doubt with including the transitive dependencies of the drools libraries, which maven would do for you automatically.  Here are the jars that were included automatically in a project I compiled with drools-core, drools-compiler, drools-api, all 5.0.1:


antlr-runtime-3.1.1.jar
core-3.4.2.v_883_R34x.jar
drools-api-5.0.1.jar
drools-compiler-5.0.1.jar
drools-core-5.0.1.jar
janino-2.5.15.jar

joda-time-1.6.jar
jsap-2.1.jar
mvel2-2.0.10.jar

This resulted from a dependencies section in the maven pom that had just this in it:

<dependencies> 
    <dependency>
        <groupId>org.drools</groupId>

       
 <artifactId>drools-core</artifactId>
        <version>5.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-compiler</artifactId>

        <version>5.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-api</artifactId>
        <version>5.0.1</version>

    </dependency>
</dependencies> 

So I suggest you give maven a try.  It makes this easy. :)

--- On Wed, 4/21/10,
 Berlin Brown <berlin.brown at gmail.com> wrote:


From: Berlin Brown <berlin.brown at gmail.com>
Subject: [rules-users] Very basic running of drools 5, basic setup and quickstart
To: rules-users at lists.jboss.org

Date: Wednesday, April 21, 2010, 12:54 AM

Is there a more comprehensive quick start for drools 5.  I was attempting to run the simple Hello World .drl rule but I wanted to do it through an ant script, possibly with just javac/java:


I get the following error:  Note: I don't am running completely without Eclipse or any other IDE:  


test:
     [java] Exception in thread "main" org.drools.RuntimeDroolsException: Unable to load d
ialect 'org.drools.rule.builder.dialect.java.JavaDialectConfiguration:java:org.drools.rule
.builder.dialect.java.JavaDialectConfiguration'


     [java]     at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuild
erConfiguration.java:274)
     [java]     at org.drools.compiler.PackageBuilderConfiguration.buildDialectConfigurati
onMap(PackageBuilderConfiguration.java:259)


     [java]     at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConf
iguration.java:176)
     [java]     at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderCo
nfiguration.java:153)


     [java]     at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:242)
     [java]     at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:142)
     [java]     at org.drools.builder.impl.KnowledgeBuilderProviderImpl.newKnowledgeBuilde


r(KnowledgeBuilderProviderImpl.java:29)
     [java]     at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(Knowledg
eBuilderFactory.java:29)
     [java]     at org.berlin.rpg.rules.Rules.rules(Rules.java:33)


     [java]     at org.berlin.rpg.rules.Rules.main(Rules.java:73)
     [java] Caused by: java.lang.RuntimeException: The Eclipse JDT Core jar is not in the
classpath
     [java]     at org.drools.rule.builder.dialect.java.JavaDialectConfiguration.setCompil


er(JavaDialectConfiguration.java:94)
     [java]     at org.drools.rule.builder.dialect.java.JavaDialectConfiguration.init(Java
DialectConfiguration.java:55)
     [java]     at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuild


erConfiguration.java:270)
     [java]     ... 9 more
     [java] Java Result: 1

...
...

I do include the following libraries with my javac and java target:

 <path id="classpath">


     <pathelement location="${lib.dir}" />
     <pathelement location="${lib.dir}/drools-api-5.0.1.jar" />
     <pathelement location="${lib.dir}/drools-compiler-5.0.1.jar" />


     <pathelement location="${lib.dir}/drools-core-5.0.1.jar" />
     <pathelement location="${lib.dir}/janino-2.5.15.jar" />
 </path>

Here is the Java code that is throwing the error.  I commented out the java.compiler code, that didn't work either.



    public void rules() {
        
        /*
        final Properties properties = new Properties();  
        properties.setProperty( "drools.dialect.java.compiler", "JANINO" );  


        PackageBuilderConfiguration cfg = new PackageBuilderConfiguration( properties );  
        JavaDialectConfiguration javaConf = (JavaDialectConfiguration)  
        cfg.getDialectConfiguration( "java" );  


        */
        final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

        // this will parse and compile in one step
        kbuilder.add(ResourceFactory.newClassPathResource("HelloWorld.drl", Rules.class), ResourceType.DRL);



        // Check the builder for errors
        if (kbuilder.hasErrors()) {
            System.out.println(kbuilder.getErrors().toString());
            throw new RuntimeException("Unable to compile \"HelloWorld.drl\".");


        }

        // Get the compiled packages (which are serializable)
        final Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();

        // Add the packages to a knowledgebase (deploy the knowledge packages).


        final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages(pkgs);

        final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
        ksession.setGlobal("list", new ArrayList<Object>());



        ksession.addEventListener(new DebugAgendaEventListener());
        ksession.addEventListener(new DebugWorkingMemoryEventListener());

        // Setup the audit logging
        KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "log/helloworld");



        final Message message = new Message();
        message.setMessage("Hello World");
        message.setStatus(Message.HELLO);
        ksession.insert(message);

        ksession.fireAllRules();


        logger.close();
        ksession.dispose();
    }

...

Here I don't think Ant is relevant because I have fork set to true:

 <target name="test" depends="compile">


     <java classname="org.berlin.rpg.rules.Rules" fork="true">
         <classpath refid="classpath.rt" />
         <classpath>
             <pathelement location="${basedir}" />


             <pathelement location="${build.classes.dir}" />
         </classpath>
     </java>
 </target>



The error is thrown at line 1.

Basically, I haven't done anything except call



final KnowledgeBuilder kbuilder = 
KnowledgeBuilderFactory.newKnowledgeBuilder();

I am running with Windows XP, Java6, and within Ant.1.7.





-- 
Berlin Brown (berlin dot brown at gmail.com)


http://botnode.com
http://berlinbrowndev.blogspot.com/


-----Inline Attachment Follows-----

_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users



      
_______________________________________________

rules-users mailing list

rules-users at lists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users





-- 
Berlin Brown (berlin dot brown at gmail.com)
http://botnode.com
http://berlinbrowndev.blogspot.com/



-----Inline Attachment Follows-----

_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100425/db8928a1/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pom.xml
Type: text/xml
Size: 3296 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20100425/db8928a1/attachment.xml 


More information about the rules-users mailing list