生成drl文件_drools中是否有任何API通过传递值动态创建drl文件?

I know how to create DRL files inside KIE workbench by using all the methods. But what my problem is without using the KIE workbench, can we create the .drl file by using our required values.If any possibility is there please suggest me. Same way suggest me any API is regarding to that. Thanks in advance.

解决方案

You can use Drools Fluent API. Try below sample code :

package com.sample;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;

import org.drools.lang.DrlDumper;

import org.drools.lang.api.DescrFactory;

import org.drools.lang.descr.PackageDescr;

@SuppressWarnings("restriction")

public class Drl_Creator {

public static void main(String str[]){

PackageDescr pkg = DescrFactory.newPackage()

.name("org.drools.example")

.newRule().name("Xyz")

.attribute("ruleflow-grou","bla")

.lhs()

.and()

.pattern("Foo").id( "$foo", false ).constraint("bar==baz").constraint("x>y").end()

.not().pattern("Bar").constraint("a+b==c").end().end()

.end()

.end()

.rhs( "System.out.println();" ).end()

.getDescr();

DrlDumper dumper=new DrlDumper();

String drl=dumper.dump(pkg);

System.out.print(drl);

try{

// create new file

File file = new File("src/main/rules/test.drl");

file.createNewFile();

FileWriter fw = new FileWriter(file.getAbsoluteFile());

BufferedWriter bw = new BufferedWriter(fw);

bw.write(drl);

// close connection

bw.close();

System.out.println("File Created Successfully");

}catch(Exception e){

System.out.println(e);

}

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值