Interesting, if I change from mvel to java and remove the package statement:
----
function String f() {
return "function";
}
rule "Invoke function"
when
eval(true)
then
System.out.println("*** f=" + f());
end
---
Then this works.
So then, what permutations of mvel/java actually work:
--------------------------------------------------------------
1. Java + Qualified package:
----
package systeminsights.plugin.core.schedule
function String f() {
return "function";
}
rule "Invoke function"
when
eval(true)
then
System.out.println("*** f=" + f());
end
---
Nope, this gives the obscure exception
org.drools.RuntimeDroolsException: java.lang.ClassNotFoundException:
systeminsights.plugin.core.schedule.Rule_Invoke_function_0ConsequenceInvoker
--------------------------------------------------------------
2. Java + simple package
----
package systeminsights
...
----
Yep, this works.
--------------------------------------------------------------
3. Mvel + qualified package + strict
Nope:
[Error: Failed to compile: 1 compilation error(s):
- (1,3) unable to resolve method using strict-mode: java.lang.Object.f()]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
--------------------------------------------------------------
4. Mvel + qualified package + non-strict
Nope:
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:975)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:915)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1121)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:698)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:664)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:198)
at
systeminsights.infra.drools.DroolsGroovyTestFixture.fireAllRules(DroolsGroovyTestFixture.groovy:89)
at
systeminsights.infra.drools.DroolsGroovyTestFixture._clinit__closure19(DroolsGroovyTestFixture.groovy:226)
at
systeminsights.infra.drools.DroolsGroovyTestFixture.getProperty(DroolsGroovyTestFixture.groovy)
at systeminsights.plugin.core.schedule.FunctionsTest.With device(_) ->
device(_) is effective(FunctionsTest.groovy:19)
Caused by: [Error: unable to access property (null parent): f]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:860)
--------------------------------------------------------------
5. Mvel + simple package + strict
----
package systeminsights
dialect "mvel"
function String f() {
return "function"
}
rule "Invoke function"
when
eval(true)
then
System.out.println("*** f=" + f())
end
---
Nope:
[Error: Failed to compile: 1 compilation error(s):
- (1,3) unable to resolve method using strict-mode: java.lang.Object.f()]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
--------------------------------------------------------------
6. Mvel + simple package + non-strict
Nope:
org.drools.runtime.rule.ConsequenceException: rule: Invoke function
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:975)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:915)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1121)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:698)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:664)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:198)
at
systeminsights.infra.drools.DroolsGroovyTestFixture.fireAllRules(DroolsGroovyTestFixture.groovy:89)
at
systeminsights.infra.drools.DroolsGroovyTestFixture._clinit__closure19(DroolsGroovyTestFixture.groovy:226)
at
systeminsights.infra.drools.DroolsGroovyTestFixture.getProperty(DroolsGroovyTestFixture.groovy)
at systeminsights.plugin.core.schedule.FunctionsTest.With device(_) ->
device(_) is effective(FunctionsTest.groovy:19)
Caused by: [Error: unable to access property (null parent): f]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:860)
--------------------------------------------------------------
7. Mvel + no package + strict
Nope:
[Error: Failed to compile: 1 compilation error(s):
- (1,3) unable to resolve method using strict-mode: java.lang.Object.f()]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at
org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:78)
--------------------------------------------------------------
8. Mvel + no package + non-strict
Nope:
Same error as 6
--
View this message in context:
http://n3.nabble.com/functions-tp60463p95682.html
Sent from the Drools - User mailing list archive at
Nabble.com.