On Aug 28, 6:47 am, viktor stolbin <[email protected]> wrote:
> Hello everybody
> I'm embedding rhino in my desktop application and faced with problem.
> In script I use hibernate Restrinctions.eq() and it gets an error when
> trying to call static "eq()". I wrote a test class and a test script:
> Test class
>
>    1. public class TestClass {
>    2.
>    3.     public static String variable = "variable";
>    4.
>    5.     public static String test(){
>    6.         return "test";
>    7.     }
>    8.
>    9. }
>
> Test script
>
>    1.
>    2. var test1 = java.lang.Math.cos(0);
>    3. var test2 =
> org.eclipse.jface.viewers.StructuredSelection.EMPTY;
>    4. var test3 = ru.griffo.core.ui.utils.TestClass.variable;
>
> It gets error:
>
>     org.mozilla.javascript.EcmaError: ReferenceError: "ru" is not
> defined. (<cmd>#1)

Unlike "com", "java", etc., "ru" is not defined by default in Rhino.
You have to prefix it with "Packages" as you've done below.
>
> Class TestClass is in the same package my script util is. When I
> changed script to:
>
>    1.
>    2. hibernate = Packages.org.hibernate.criterion;
>    3. jface = Packages.org.eclipse.jface.viewers;
>    4. test = Packages.ru.griffo.core.ui.utils;
>    5.
>    6. var test1 = java.lang.Math.cos(0);
>    7. var test2 = jface.StructuredSelection.EMPTY;
>    8. var test3 = test.TestClass.variable;
>    9. var test4 = test.TestClass.test();
>
> it gets the same error I get with hibernate Restriqtions.eq():
>
>     org.mozilla.javascript.EcmaError: TypeError: Cannot call property
> test in object [JavaPackage ru.griffo.core.ui.utils.TestClass]. It is
> not a function, it is "object". (<cmd>#1)

The fact that it thinks that ru.griffo.core.ui.utils.TestClass is a
package rather than a class tells me that there's some kind of
classpath problem. Is the TestClass in the classpath? Perhaps you're
using the -jar option to "java" so that it ignores the classpath?

>
> I tried to use Importers and get this error again.
>
> Script util class
>
>    1. private org.mozilla.javascript.Context scriptContext;
>    2. private Scriptable scriptScope;
>    3.
>    4. private void initServices() {
>    5. scriptContext = org.mozilla.javascript.Context.enter();
>    6. scriptScope = new ImporterTopLevel(scriptContext);
>    7.
>    8. registerToScriptEngine("out", System.out);
>    9. registerToScriptEngine("boTool", boTool);
>   10. registerToScriptEngine("convertTool", convertTool);
>   11. registerToScriptEngine("entityDAO", entityDAO);
>   12. }
>
> Please, help me to solve this problem

_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to