我有一个问题豆壳 http://www.beanshell.org/manual/bshmanual.html我在任何地方都找不到答案。我只能通过以下两种方式之一运行 Beanshell 脚本:
其中Classpath是在调用Beanshell之前定义的,并且Beanshell使用
JRE 默认类加载器。
在启动 Beanshell 之前根本没有定义类路径,然后我使用addClassPath()
and importCommands()
动态构建类路径
在 Beanshell 的类加载器中。这个方法好像没有继承jars
这是默认 JRE 类加载器的一部分。
经过多次实验,我了解到我无法使用预定义的类路径启动脚本,然后能够使用以下命令添加到类路径addClassPath()
。我不知道这是否是设计的或者如果我做错了什么?
你自己很容易看出我的问题是什么。例如,以下是脚本:
::Test.bat (where bsh.jar exists in JRE/lib/ext directory)
@echo off
set JAVA_HOME=C:\JDK1.6.0_27
:: first invoke: this first command works
%JAVA_HOME%\jre\bin\java.exe bsh.Interpreter Test.bsh
:: second invoke: this command fails
%JAVA_HOME%\jre\bin\java.exe -cp ant.jar bsh.Interpreter Test.bsh
第二次调用会导致此错误:
Evaluation Error: Sourced file: Test.bsh : Command not
found: helloWorld() : at Line: 5 : in file: Test.bsh : helloWorld ( )
Test.bat 启动这个 Beanshell 脚本:
// Test.bsh
System.out.println("Trying to load commands at: " + "bin" );
addClassPath("bin");
importCommands("bin");
helloWorld();
而且,这是我的 hello World.bash 脚本:
// File: helloWorld.bsh
helloWorld() {
System.out.println("Hello World!");
}