You can compile DRL and display all the errors using a simple Java program. (In fact, many apps compile their DRL on the fly.) To run such a program from the command line, use a simple shell script (or .bat file) that establishes the Java environment (JAVA_HOME) and the classpath, according to your application, and the essential Drools jars. Below is a shell script doing this on my Linux box; Windows should be similar. Note that the exact names of the jars need not be the same as given here.<br>
<br><br>export JAVA_HOME=/extra/JDK6u23/jdk1.6.0_23<br>javac=$JAVA_HOME/bin/javac<br>java=$JAVA_HOME/bin/java<br><br>export CLASSPATH=.:/extra/drools/droolsjbpm/drools/drools-core/target/drools-core-5.3.0-SNAPSHOT.jar:/extra/drools/droolsjbpm/droolsjbpm-knowledge/knowledge-api/target/knowledge-api-5.3.0-SNAPSHOT.jar:/extra/drools/droolsjbpm/drools/drools-compiler/target/drools-compiler-5.3.0-SNAPSHOT.jar:/home/wlaun/.m2/repository/org/eclipse/jdt/core/compiler/ecj/3.5.1/ecj-3.5.1.jar:/extra/antlr/antlrworks-1.4.jar:/extra/drools/droolsjbpm/droolsjbpm-build-distribution/osgi-bundles/plugins/mvel2-2.1.0.drools1.jar<br>
<br>j="$(find $sub -name \*.java) $(find drools -name \*.java) $(find cc -name \*.java)"<br>echo "compiling $j."<br><br>$javac $j<br>$java DroolsMain<br><br>=============================================<br>
<br>Here's the Java code I use for compiling with the above shell script:<br><br>import org.drools.KnowledgeBase;<br>import org.drools.KnowledgeBaseConfiguration;<br>import org.drools.KnowledgeBaseFactory;<br>import org.drools.builder.KnowledgeBuilder;<br>
import org.drools.builder.KnowledgeBuilderError;<br>import org.drools.builder.KnowledgeBuilderErrors;<br>import org.drools.builder.KnowledgeBuilderFactory;<br>import org.drools.conf.ConsequenceExceptionHandlerOption;<br>import org.drools.definition.KnowledgePackage;<br>
import org.drools.io.Resource;<br>import org.drools.io.ResourceFactory;<br>import org.drools.builder.ResourceType;<br>import org.drools.runtime.StatefulKnowledgeSession;<br><br> KnowledgeBaseConfiguration kBaseConfig =<br>
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br> @SuppressWarnings("unchecked")<br> ConsequenceExceptionHandlerOption cehOption =<br> ConsequenceExceptionHandlerOption.get( (Class<? extends ConsequenceExceptionHandler>)MyConsExHandler.class );<br>
kBaseConfig.setOption( cehOption );<br> kBase = KnowledgeBaseFactory.newKnowledgeBase( kBaseConfig );<br> <br> KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();<br> String drlPath = ...;<br>
if( drlPath != null ){<br> Resource drl = ResourceFactory.newClassPathResource( drlPath, getClass() );<br> kBuilder.add( drl, ResourceType.DRL );<br> }<br><br> if( kBuilder.hasErrors() ){<br>
System.err.println( "### compilation errors ###" );<br> KnowledgeBuilderErrors errors = kBuilder.getErrors();<br> for( KnowledgeBuilderError err: errors ){<br> System.err.println( err.toString() );<br>
}<br> return;<br> }<br><br> kBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );<br> session = kBase.newStatefulKnowledgeSession();<br><br><br>Cheers<br>-W<br><br><br>
<br><div class="gmail_quote">On 30 October 2011 17:32, arrehman <span dir="ltr"><<a href="mailto:arrehman73@yahoo.com">arrehman73@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
I am using Drools 5.2 (direclty, not via grails plugins) in a grails<br>
2.0.0.M2 web application. I use IntelliJ IDEA for development which does not<br>
support Drools inherently. (I know eclipse has better support) I am<br>
struggling with the compilations, syntax erros of .DRL file I have in my<br>
app. Are there any command line tools that will help me point out the exact<br>
syntax errors of the DRL file? Currently I am struggling, and doing a adhoc<br>
approach. I know there must be a better way.<br>
<br>
Thanks,<br>
Abdul<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Drools-command-line-tools-tp3465973p3465973.html" target="_blank">http://drools.46999.n3.nabble.com/Drools-command-line-tools-tp3465973p3465973.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>