drools 5 的非常基本的运行、基本设置和快速入门
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 代码,它也不起作用。
public voidrules() {
/*
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行抛出
之外,我没有做任何事情
。基本上,除了调用final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory .newKnowledgeBuilder();
我正在使用 Windows XP、Java6 和 Ant.1.7 运行。 Drools-Rules 的最新(截至昨天)版本 5。
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:
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.
The most recent (as of yesterday) version 5 of Drools-Rules.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题的关键是错误列表中的这一行:
“Caused by: java.lang.RuntimeException: The Eclipse JDT Core jar is not in the classpath”
此引用是由 Eclipse Drools 插件安装的库“core-3.4.2.v_883_R34x.jar”
如果添加 core -3.4.2.v_883_R34x.jar 添加到您的库中,那么您将不会遇到运行时异常。
the key to the problem is this line in the error listing:
"Caused by: java.lang.RuntimeException: The Eclipse JDT Core jar is not in the classpath"
This reference is 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 then you won't get the runtime exception.
我尝试了 drools-5.0-examples HelloWorld,然后使用 Maven 尝试了您的示例代码,并设法让它工作。然后,我构建了一个具有您描述的特征的 Ant 构建文件,并得到了与您完全相同的结果。
我注意到 Maven 版本包含更多依赖库。如果我将这些依赖项从 Maven 复制到 Ant 版本“lib”目录中并更新 build.xml 以包含这些依赖项,那么您的代码可以正常工作。
I tried the drools-5.0-examples HelloWorld and then your example code using Maven and managed to get it working. I then constructed an Ant build file with the characteristics that you describe and got exactly the same result that you did.
I noticed that the Maven version contains many more dependent libraries. If I copy these dependencies from Maven into Ant version "lib" directory and update the build.xml to include these then your code works fine.