I want to declare a global variable in a drools rule file (mvel). This is because this global is used in all the rules as a parameter to another function. I could easily pass this string explicitly in every call to the function, but this makes it hard if the string changes.
I thought I could do a:
global String someStr = "some string";
But on compile, I get:
[11,31]: [ERR 107] Line 11:31 mismatched input '=' expecting one of the following tokens: '[package, import, global, declare, function, rule, query]'.
So obviously, I can't assign it this way. Nor do I seem to be able to declare a class and a string in that class to reference through the class.
So I found I could so something that seems silly:
global String someStr;
rule "Initialize"
when
then
someStr = "some string";
end
This seems to work, but, this will log every single time this rule matches (always) to just assign a global.
Is there a better way that I'm missing???