Bonjour,
J'aimerais pouvoir executer une fonction écrite dans Java depuis mon script groovy. Mon script actuel est celui ci (je ne suis pas sur que passer par setProperty soit la bonne démarche) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| GroovyShell shell = new GroovyShell();
Script script;
try {
// Chargement du script groovy
script = shell.parse(scriptGroovy);
Binding binding = new Binding();
//variables
binding.setVariable("code", code);
//fonction
JmxBuilder builder = new JmxBuilder();
binding.setProperty("transformation", new Closure(builder) {
public Object call(Object[] args) {
String chaine=args[0].toString();
return transformation(chaine);
}
});
//execution
script.run();
Binding sortie=script.getBinding();
//sortie
String name=null,price=null;
try {
name=(String) sortie.getVariable("name").toString();
} catch (Exception e) {
} |
Mais lorsque j'écris dans mon script Groovy
transformation("ma chaiNe")
Cela me retourne une erreur "No signature of method: Script1.transformation() is applicable for argument types: (java.lang.String) values: [ma chaiNe]"
J'ai à tout prix besoin de repasser dans Java, je ne peux pas faire une fonction Groovy qui ferait ce que fait la fonction transformation
Partager