Unknown macro: floating-toc

Scripting in NetBeans

BeanShell Script File Development with NetBeans

The NetBeans software is available as download on the  NetBeans Website. We provide a sample project for Script Files created with NetBeans. For detailed information have a look at chapter First, after installing NetBeans IDE a new project has to be created or loaded. If a project is loaded, go to third to continue.


Categories: Java Projects: Java application


  • Second, set project name and project location.


  • Third, set jBEAM.jar as library:

First of all, right click on Libraries. Afterwards, click on the button Create -> new library


Library name -> OK


Select Tab “Classpath”
 -> Add JAR/Folder…
 -> Select jBEAM.jar -> OK


After finishing the import of jBEAM library.


Creating of Script Files in NetBeans

First, create a main class to start script method.

public class Main {
public static void main(String[] args) {
 // Instance of new Scripting class.
 Scripting scripting = new Scripting();
 // Start script which is defined in the scripting class.

Second, create a Scripting class: for script files, the scripting() method is important. The scripting method can be copied and inserted in a BSH File which is edited by Note Pad.

import com.AMS.jBEAM.*;
import org.asam.cea.Cea2Bus.*;

class Scripting {
// Declaration of Variables. These Variables also exist in jBEAM, therefore, they need not to be typed in a script file.
// If the package com.AMS.jBEAM.* is imported in the top of class, the sequence com.AMS.jBEAM can be ignored.
 jBEAM jB;
  ScriptService jS;
  ComponentManager jC;
  DesktopManager jG;
  DataItemManager jD;
  org.asam.cea.Cea2Bus.Cea2BusIF cea2Bus;

 // Constructor of scripting class
 Scripting() {
  // Initialize the internal variables of the scripting service.
         jB = newjBEAM();
          jS = (ScriptService) jB.getScriptService();
          jC = (ComponentManager) jB.getComponentManager();
          jG = (DesktopManager) jB.getDesktopManager();
          jD = (DataItemManager) jB.getDataItemManager();
          cea2Bus = (Cea2BusIF) jB.getDataItemManager();
 // init of new jBEAM – method newjBEAM returns new jBEAM
 private jBEAM newjBEAM() {
  if (jB != null) {
   return jB;
       // Make an instance of jBEAM
  try {
    jB = new jBEAM(); // it's a 'Printable' JFrame
  } catch (Exception exc) {
   * Parameters for the hash table with presetting: String "Locale" Locale
   * "MenuBar" Boolean "LoggerStartCondition" Boolean "PreferredDataArraySize" Integer
   * "WindowTitle" String "WindowRectangle" Rectangle

   HashMap<String, Object> preSettings = new HashMap<String, Object>();
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  int x = 5;
  int y = 5;
  int requestedWidth = 500;
  int requestedHeight = 400;
   preSettings.put("WindowRectangle", new Rectangle(x, y, requestedWidth, requestedHeight));
   preSettings.put("MenuBar", new Boolean(true));
   preSettings.put("LoggerStartCondition", "Warning");
   preSettings.put("WINDOW_TITLE", "jBEAM for Scripting");
  try {
    jB.init(this, preSettings); // start jBEAM
  } catch (Exception exc) {
        } catch (Error err) {
       return null;
        return jB;
 void runScript (){
  // Special script method -> can be copied in a bsh file
  // First, delete all existing components.

Start script in NetBeans

Click on the beanshell_netbeans9.png button to start the program in NetBeans.

Click on thebeanshell_netbeans10.png button to debug the script.

To toggle breakpoints, click in the gray frame in front of the starting line.


External links


Copyright by Kistler Chemnitz GmbH 2021
XWiki Enterprise 4.4 - Documentation