是否有更全面的 drools 5 快速入门。我试图运行简单的 Hello World .drl 规则,但我想通过一个 ant 脚本来完成,可能只使用 javac/java:
我收到以下错误:注意:如果没有 Eclipse 或任何其他 IDE,我不会完全运行:
是否有更全面的 drools 5 快速入门。我试图运行简单的 Hello World .drl 规则,但我想通过一个 ant 脚本来完成,可能只使用 javac/java:
我收到以下错误:注意:如果没有 Eclipse 或任何其他 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
...
...
我的 javac 和 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>
这是引发错误的 Java 代码。我注释掉了 java.compiler 代码,它也不起作用。
公共无效规则(){
/*
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();
}
...
在这里,我认为 Ant 无关紧要,因为我将 fork 设置为 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>
错误在第 1 行抛出。
基本上,除了打电话,我什么都没做
最终 KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
我在 Windows XP、Java6 和 Ant.1.7 中运行。Drools-Rules 的最新(截至昨天)版本 5。