Problem calling a compiled method

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problem calling a compiled method

lobesquare
Hello,

referring to http://www.beanshell.org/manual/commands.html (Section Compiled Commands) I implemented a class

package beanShellTest1;

import bsh.CallStack;
import bsh.Interpreter;

public class Test {

        public static void invoke(Interpreter env, CallStack callstack)
        {
                System.out.println("Test() called.");
        }
       
}

and tried to call this class via

public class BeanShellTest1 {

        public static void main(String[] args) {
                Interpreter interpreter = new Interpreter();
                try {
                        interpreter.eval("cp = getClassPath(); print (cp)");
                        interpreter.eval("Test()");
                } catch (EvalError e) {
                        e.printStackTrace();
                }
               
        }
}

Unfortunately I get a

Sourced file: inline evaluation of: ``Test();'' : Command not found: Test() : at Line: 1 : in file: inline evaluation of: ``Test();'' : Test ( )

        at bsh.Name.invokeLocalMethod(Unknown Source)
        at bsh.Name.invokeMethod(Unknown Source)
        at bsh.BSHMethodInvocation.eval(Unknown Source)
        at bsh.BSHPrimaryExpression.eval(Unknown Source)
        at bsh.BSHPrimaryExpression.eval(Unknown Source)
        at bsh.Interpreter.eval(Unknown Source)
        at bsh.Interpreter.eval(Unknown Source)
        at bsh.Interpreter.eval(Unknown Source)
        at beanShellTest1.BeanShellTest1.main(BeanShellTest1.java:30)

Does anyone have a hint what is wrong? The classpath (previously printed) seems to be correct.

Greetings

   lobequadrat
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem calling a compiled method

alexander_a_sokolov
Try to use addClassPath and importCommands before call your method.
lobesquare wrote
Hello,

referring to http://www.beanshell.org/manual/commands.html (Section Compiled Commands) I implemented a class

package beanShellTest1;

import bsh.CallStack;
import bsh.Interpreter;

public class Test {

        public static void invoke(Interpreter env, CallStack callstack)
        {
                System.out.println("Test() called.");
        }
       
}

and tried to call this class via

public class BeanShellTest1 {

        public static void main(String[] args) {
                Interpreter interpreter = new Interpreter();
                try {
                        interpreter.eval("cp = getClassPath(); print (cp)");
                        interpreter.eval("Test()");
                } catch (EvalError e) {
                        e.printStackTrace();
                }
               
        }
}

Unfortunately I get a

Sourced file: inline evaluation of: ``Test();'' : Command not found: Test() : at Line: 1 : in file: inline evaluation of: ``Test();'' : Test ( )

        at bsh.Name.invokeLocalMethod(Unknown Source)
        at bsh.Name.invokeMethod(Unknown Source)
        at bsh.BSHMethodInvocation.eval(Unknown Source)
        at bsh.BSHPrimaryExpression.eval(Unknown Source)
        at bsh.BSHPrimaryExpression.eval(Unknown Source)
        at bsh.Interpreter.eval(Unknown Source)
        at bsh.Interpreter.eval(Unknown Source)
        at bsh.Interpreter.eval(Unknown Source)
        at beanShellTest1.BeanShellTest1.main(BeanShellTest1.java:30)

Does anyone have a hint what is wrong? The classpath (previously printed) seems to be correct.

Greetings

   lobequadrat
Loading...