Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7440889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:55:18+00:00 2026-05-29T10:55:18+00:00

I have a question about Beanshell that I can’t find an answer to anywhere.

  • 0

I have a question about Beanshell that I can’t find an answer to anywhere. I am only able to run Beanshell scripts in 1 of 2 ways:

  1. Where Classpath is defined before invoking Beanshell and Beanshell uses
    the JRE default classloader.

  2. Where no classpath is defined at all before starting Beanshell and then I use
    addClassPath() and importCommands() to dynamically build the classpath
    within Beanshell’s classloader. This method does not seem to inherit a jars
    that were part of the default JRE classloader.

After much experimentation, I have learned that I am unable to start a script with a pre-defined Classpath and then be able to add to the classpath by using addClassPath(). I don’t know if this is as-designed or if I am doing something wrong?

It is very easy to see for yourself what my problem is. For example, here is the script:

::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

The second invoke causes this error:

Evaluation Error: Sourced file: Test.bsh : Command not 
found: helloWorld() : at Line: 5 : in file: Test.bsh : helloWorld ( )

Test.bat launches this Beanshell script:

// Test.bsh
System.out.println("Trying to load commands at: " + "bin" );
addClassPath("bin");  
importCommands("bin");
helloWorld();

And, this is my helloWorld.bsh script:

// File: helloWorld.bsh
helloWorld() { 
    System.out.println("Hello World!");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:55:19+00:00Added an answer on May 29, 2026 at 10:55 am

    Your Test.bsh has a slight error: importCommands looks for a directory called “bin” in the class path and loads all .bsh files from there, so what you should add to addClassPath is the current directory:

    // Test.bsh
    System.out.println("Trying to load commands at: " + "bin" );
    addClassPath(".");  // current directory
    importCommands("bin");
    helloWorld();
    

    The code you had works in the first case because the current directory is in the default system class path. The problem is that the -cp switch overrides the default class path, so importCommands no longer has any way to find the bin directory.

    Alternatively you can add . to the classpath on the JVM level:

    %JAVA_HOME%\jre\bin\java.exe -cp .;ant.jar bsh.Interpreter Test.bsh
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this question about umbraco structuring and I can't find the answer anywhere.
I have a question about equivalent search result, that can occur on different fields.
I have a question about locking. This doesn't have to be only about record
I have question about database optimizing, indexing. I have table that called projects and
Have a question about VBS: How can i start a new window (e.g. of
i have a question about fopen() and base64 comunication. The scenario is that: i
I'm learning asp.net. I have question about example buttons I can use two types
Have a question about full text search. I have a query that works, but
I have a question about: how can I use foreach the service's namespaces in
I have a question about local classes in Java (classes that declares in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.