Hello all,

I would like to realize a test with LSC inside a JavaScript code for a dataset. 
Inside this code i would like to import my own Java class. I try to read some 
documentation like 
http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/java_script.html
 and also 
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scripting_Java 
but with partial success.

So i made a little test with Rhino (I'm not a Java specialist but i would like 
to understand my mistake) and java 1.8.0_60. I made some tests with Java 1.7 
but there is more issue with it.

Here is my steps :

1/ My own Java class created under Eclipse, this is a very simple example like 
an HelloWorld :-) :

package concat;

public class Concat { 
 public static String Ajout(String chaine) {
 //System.out.println("Methode concat " + chaine);
 return new String(chaine + " fonction ajout");
 }
}

2/ I export this package as a jar file concat.jar, and i copy it inside LSC lib 
(lib64) directory
3/ I check the package with Rhino provided inside LSC like this with 
ajava_script code :
$ cat ${HOME}/test.js 
importPackage(Packages.concat);
var str = new Concat();
print(str.Ajout("This is a simple test string") + "\n");

Here the Rhino test :
$ ${JAVA_HOME}/bin/java -cp lib64/rhino-1.7R4.jar:lib64/concat.jar 
org.mozilla.java_script.tools.shell.Main ${HOME}/test.js 
This is a simple test string fonction ajout
$

4/ Now i have a simple LSC instance with a dataset defined like this :
 <dataset>
 <name>domaine</name>
 <policy>FORCE</policy>
 <forceValues>
 <string><![CDATA[rjs:
importPackage(Packages.concat);
var str = new Concat();
print(str.Ajout("This is a simple test string") + "\n");
str.Ajout("This is a simple test string")+"";
 ]]></string>
 </forceValues>
 </dataset>

It runs correctly but if i insert the same code inside an external file with 
scriptInclude and "rjs:" call, i have this error :

ERROR - org.mozilla.javascript.EcmaError: ReferenceError: "importPackage" is 
not defined. 

If you have any ideas... 

Thanks,
--

Frederic Poisson
_______________________________________________________________
Ldap Synchronization Connector (LSC) - http://lsc-project.org

lsc-users mailing list
[email protected]
http://lists.lsc-project.org/listinfo/lsc-users

Reply via email to