Well, I'm probably not doing something wrong, but I am having a problem
with the "source" method of Interpreter. Here is the problem.

1. create a script file, hello.java, with just one line in it: 
------------------------------------------------------
print("hello");
---------------------------------------------------------

2. bring up a bsh shell in emacs and type:
bsh % import bsh.*;
bsh % Interpreter i = new Interpreter();
bsh % i.source("<fill in the path to file>/hello.java");
// Error: Unknown error: java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
      at bsh.Reflect.findExtendedMethod(Reflect.java, Compiled Code)
      at bsh.Reflect.invokeMethod(Reflect.java, Compiled Code)
      at bsh.Reflect.invokeObjectMethod(Reflect.java:106)
      at bsh.Reflect.invokeMethod(Reflect.java:69)
      at bsh.ASTMethodInvocation.eval(ASTMethodInvocation.java:12)
      at bsh.ASTPrimaryExpression.eval(ASTPrimaryExpression.java,
Compiled Code)
      at bsh.Interpreter.run(Interpreter.java, Compiled Code)
      at bsh.Interpreter.main(Interpreter.java:163)
bsh % 

Why am I getting this error?

If instead, I do essentially the same thing from within a class, things
work as expected. That is, create a file HelloMain.java:

-----------------------------------------------

import bsh.*;

public class HelloMain {
    public static void main(String[] args)
      throws EvalError, java.io.FileNotFoundException
    {
      Interpreter i = new Interpreter();
      i.source("c:/chuck/java/src/beanshell/hello.java");
    }
}
---------------------------------------------------------

Then, compile and run it. Whereupon I get the expected result:

------------------------------------------------------------------------
-----
cd c:/Chuck/java/src/beanshell/
javaw -classpath
.;c:/chuck/java/classes;c:/weblogic/classes;/weblogic/lib/weblogicaux.ja
r;c:/weblogic/classes;c:/weblogic/license;c:/weblogic/myserver/servercla
sses;c:/chuck/java/src;c:/chuck/java/lib/bsh-1.0.jar HelloMain

hello

Process HelloMain finished
------------------------------------------------------------------------
-------------

Thank you for your help.

Chuck

Reply via email to