Very easy to start drooling 5, basic setup and quick start

Is there a more complete quick start for drools 5. I tried to run a simple Hello World.drl rule, but I wanted to do this through an ant script, possibly only with javac / java:

I get the following error: Note: I do not start completely without Eclipse or any other IDE:

Is there a more complete quick start for drools 5. I tried to run a simple Hello World.drl rule, but I wanted to do this through an ant script, possibly only with javac / java:

I get the following error: Note: I do not start 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 include the following libraries with my goal of javac and java:

  <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 throws an error. I commented on java.compiler code, which 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 do not think that ant matters, 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 displayed on line 1.

Basically, I did nothing but call

final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder ();

I work with Windows XP, Java6 and inside Ant.1.7. The most recent (as of yesterday) version 5 of the Drools-Rules rules.

+1
java jboss rules drools
source share
2 answers

The key to the problem is this line in the error list: "Called: java.lang.RuntimeException: Eclipse core JDT kernel is not in the classpath"

This link refers to the library "core-3.4.2.v_883_R34x.jar", which is installed by the Eclipse Drools plugin

If you add core-3.4.2.v_883_R34x.jar to your libraries, you will not get an exception at runtime.

+9
source share

I tried the drools-5.0 examples - HelloWorld, and then your sample code using Maven and was able to get it working. Then I built the Ant build file with the characteristics that you describe, and got exactly the same result as you.

I noticed that the Maven version contains many more dependent libraries. If I copy these dependencies from Maven to the Ant version "lib" directory and update build.xml to include them, then your code will work fine.

 <path id="classpath.rt"> <pathelement location="${lib.dir}/antlr-runtime-3.1.1.jar" /> <pathelement location="${lib.dir}/core-3.4.2.v_883_R34x.jar" /> <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}/drools-transformer-xstream-5.0.1.jar" /> <pathelement location="${lib.dir}/janino-2.5.15.jar" /> <pathelement location="${lib.dir}/joda-time-1.6.jar" /> <pathelement location="${lib.dir}/mvel2-2.0.10.jar" /> <pathelement location="${lib.dir}/xpp3_min-1.1.4c.jar" /> <pathelement location="${lib.dir}/xstream-1.3.1.jar" /> </path> 
+2
source share

All Articles