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.
export JAVA_HOME=/extra/JDK6u23/jdk1.6.0_23
javac=$JAVA_HOME/bin/javac
java=$JAVA_HOME/bin/java
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
j="$(find $sub -name \*.java) $(find drools -name \*.java) $(find cc -name
\*.java)"
echo "compiling $j."
$javac $j
$java DroolsMain
=============================================
Here's the Java code I use for compiling with the above shell script:
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseConfiguration;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.conf.ConsequenceExceptionHandlerOption;
import org.drools.definition.KnowledgePackage;
import org.drools.io.Resource;
import org.drools.io.ResourceFactory;
import org.drools.builder.ResourceType;
import org.drools.runtime.StatefulKnowledgeSession;
KnowledgeBaseConfiguration kBaseConfig =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
@SuppressWarnings("unchecked")
ConsequenceExceptionHandlerOption cehOption =
ConsequenceExceptionHandlerOption.get( (Class<? extends
ConsequenceExceptionHandler>)MyConsExHandler.class );
kBaseConfig.setOption( cehOption );
kBase = KnowledgeBaseFactory.newKnowledgeBase( kBaseConfig );
KnowledgeBuilder kBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
String drlPath = ...;
if( drlPath != null ){
Resource drl = ResourceFactory.newClassPathResource( drlPath,
getClass() );
kBuilder.add( drl, ResourceType.DRL );
}
if( kBuilder.hasErrors() ){
System.err.println( "### compilation errors ###" );
KnowledgeBuilderErrors errors = kBuilder.getErrors();
for( KnowledgeBuilderError err: errors ){
System.err.println( err.toString() );
}
return;
}
kBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );
session = kBase.newStatefulKnowledgeSession();
Cheers
-W
On 30 October 2011 17:32, arrehman <arrehman73(a)yahoo.com> wrote:
Hi,
I am using Drools 5.2 (direclty, not via grails plugins) in a grails
2.0.0.M2 web application. I use IntelliJ IDEA for development which does
not
support Drools inherently. (I know eclipse has better support) I am
struggling with the compilations, syntax erros of .DRL file I have in my
app. Are there any command line tools that will help me point out the exact
syntax errors of the DRL file? Currently I am struggling, and doing a adhoc
approach. I know there must be a better way.
Thanks,
Abdul
--
View this message in context:
http://drools.46999.n3.nabble.com/Drools-command-line-tools-tp3465973p346...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users