Issue #795 has been reported by Frédéric POISSON.

----------------------------------------
Bug #795: Rhino with scriptInclude do not understand importPackage function
http://tools.lsc-project.org/issues/795

Author: Frédéric POISSON
Status: New
Priority: Normal
Assigned to: 
Category: 
Target version: 
Problem in version: 2.1.3


Hello,

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 issues with it.

Here are my steps :

1/ My own Java class created under Eclipse, this is a very simple example like 
an HelloWorld :-) :
<pre>
package concat;

public class Concat {   
    public static String Ajout(String chaine) {
        //System.out.println("Methode concat " + chaine);
        return new String(chaine + " fonction ajout");
    }
}
</pre>
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 a 
JavaScript code :
<pre>$ cat ${HOME}/test.js    
importPackage(Packages.concat);
var str = new Concat();
print(str.Ajout("This is a simple test string") + "\n");
</pre>
Here the Rhino test :
<pre>$ ${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
$
</pre>
4/ Now i have a simple LSC instance with a dataset defined like this :
<pre>
        <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>
</pre>
It runs correctly but if i insert the same code inside an external file with 
scriptInclude and "rjs:"  call, i have this error :

<pre>ERROR - org.mozilla.java_script.EcmaError: ReferenceError: "importPackage" 
is not defined.</pre>




-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://tools.lsc-project.org/my/account
_______________________________________________________________
Ldap Synchronization Connector (LSC) - http://lsc-project.org

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

Reply via email to