Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
63 views
in Technique[技术] by (71.8m points)

java - Drools function access

I have a .drl file which serves as a common file for functions for my various rule files.

This .drl file which holds my common functions is in package com.sample.common. (file: a_common.drl)

I have a rule file which is also in package com.sample.common and the rules execute just fine. (file: rule1.drl)

I have a rule file which is in package com.sample.common.anotherpackage and the rules fail due to the function call not being available. (file: rule2.drl)

If I have read the various posts on this subject correctly, there is no easy way to make both of my rule files ( rule1.drl & rule2.drl ) access the common rule file a_common.drl unless I change the package name of rule2.drl to com.sample.common...

I am aware that I could do something by adjusting Java code outside of the .drl files; however, in my case I need to stick to working with functions in .drl files.

File: a_common.drl

package com.sample.common

function boolean getFirstX(String string, int x){
    ...somecode
    return (string != null);
}

function boolean getNextX(String string, int x){
    ...somecode
    return (string != null);
}

File: rule1.drl ( function getFirstX works fine )

package com.sample.common

rule "Hello World"
    
    when
        
        eval( getFirstX("somevalue") )
        
    then
       ....do something

end

File: rule2.drl ( function getFirstX is not found )

package com.sample.common.anotherpackage

rule "Hello World"
    
    when
        
        eval( getFirstX("somevalue") )
        
    then
       ....do something

end
question from:https://stackoverflow.com/questions/65924085/drools-function-access

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...