{"id":6686,"library":"java-access-bridge-wrapper","title":"java-access-bridge-wrapper","description":"java-access-bridge-wrapper is a Python wrapper for the Windows Java Access Bridge (JAB). It enables Python applications to interact with and automate Java user interfaces on the Windows operating system. This library, currently at version 2.0.0, is primarily designed for 64-bit Windows environments and Java Development Kit (JDK) or Java Runtime Environment (JRE) versions 8 or higher.","status":"active","version":"2.0.0","language":"en","source_language":"en","source_url":"https://github.com/robocorp/java-access-bridge-wrapper.git","tags":["windows","java","automation","gui","accessibility"],"install":[{"cmd":"pip install java-access-bridge-wrapper","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"JavaAccessBridgeWrapper","correct":"from JABWrapper.jab_wrapper import JavaAccessBridgeWrapper"},{"symbol":"ContextNode","correct":"from JABWrapper.context_tree import ContextNode"},{"symbol":"ContextTree","correct":"from JABWrapper.context_tree import ContextTree"},{"symbol":"SearchElement","correct":"from JABWrapper.context_tree import SearchElement"}],"quickstart":{"code":"import ctypes\nimport queue\nimport threading\nimport time\nfrom ctypes import wintypes, byref\n\nfrom JABWrapper.jab_wrapper import JavaAccessBridgeWrapper\nfrom JABWrapper.context_tree import ContextTree # Optional, for element interaction\n\ndef pump_background(pipe: queue.Queue):\n    \"\"\"Runs the Windows message pump in a background thread.\"\"\"\n    try:\n        jab_wrapper = JavaAccessBridgeWrapper()\n        pipe.put(jab_wrapper)\n        message = byref(wintypes.MSG())\n        # The message pump is essential for JAB to receive events\n        while ctypes.windll.user32.GetMessageW(message, 0, 0, 0) > 0:\n            ctypes.windll.user32.TranslateMessage(message)\n            ctypes.windll.user32.DispatchMessageW(message)\n    except Exception as err:\n        pipe.put(None)\n        print(f\"Error in message pump: {err}\")\n\ndef main():\n    pipe = queue.Queue()\n    # Start the message pump in a separate thread\n    thread = threading.Thread(target=pump_background, daemon=True, args=[pipe])\n    thread.start()\n\n    # Retrieve the initialized JABWrapper object from the background thread\n    jab_wrapper = pipe.get()\n    if not jab_wrapper:\n        raise Exception(\"Failed to initialize Java Access Bridge Wrapper\")\n\n    print(\"Java Access Bridge Wrapper initialized.\")\n\n    # Give JAB a moment to process initial messages\n    time.sleep(0.5)\n\n    # Example: List available Java windows (requires a Java app running)\n    try:\n        windows = jab_wrapper.get_windows()\n        if windows:\n            print(\"\\nDiscovered Java Windows:\")\n            for i, window in enumerate(windows):\n                print(f\"  [{i+1}] Title: {window.title}, PID: {window.pid}\")\n\n            # Example: Attach to the first Java window found (if any)\n            if len(windows) > 0:\n                first_window = windows[0]\n                print(f\"\\nAttempting to switch to: {first_window.title}\")\n                jab_wrapper.switch_window_by_title(first_window.title)\n                print(f\"Successfully switched to window: {jab_wrapper.get_main_frame_title()}\")\n\n                # Optional: Get and print the context tree of the active window\n                print(\"\\nBuilding context tree...\")\n                context_tree = ContextTree(jab_wrapper)\n                # This can be very verbose, only print a few levels or specific elements\n                # For a full tree, consider pretty-printing or specific searches\n                # print(context_tree.get_tree_string())\n                print(f\"Root element role: {context_tree.get_root().role}, name: {context_tree.get_root().name}\")\n\n        else:\n            print(\"No Java windows found. Please ensure a Java application is running.\")\n\n    except Exception as e:\n        print(f\"An error occurred during interaction: {e}\")\n\n    finally:\n        print(\"\\nShutting down Java Access Bridge Wrapper.\")\n        if jab_wrapper:\n            jab_wrapper.shutdown()\n        thread.join(timeout=1) # Give the thread a moment to finish cleanly\n\nif __name__ == \"__main__\":\n    # Ensure Java Access Bridge is enabled and a Java application is running.\n    # For testing, you might need a simple Swing/AWT app.\n    main()","lang":"python","description":"This quickstart demonstrates how to initialize the `JavaAccessBridgeWrapper` by setting up the necessary Windows message pump in a separate thread, which is crucial for the Java Access Bridge to receive UI events. It then attempts to list active Java windows and interact with the first detected Java application by switching to its context. It also shows an optional step to build a `ContextTree` to explore the UI elements. Before running, ensure a 64-bit Java application is open and the Java Access Bridge is enabled on your Windows system."},"warnings":[{"fix":"Ensure your Windows OS and all Java environments (JDK/JRE) are 64-bit. Target only 64-bit Java applications.","message":"The library explicitly supports only 64-bit Windows operating systems. Using it with 32-bit Windows or 32-bit Java applications is not supported and will likely result in errors or unexpected behavior. Ensure your Java installation and target application are 64-bit.","severity":"breaking","affected_versions":"All versions"},{"fix":"Open a command prompt as administrator, navigate to your Java `bin` directory (e.g., `C:\\Program Files\\Java\\jre<version>\\bin`), and run `jabswitch.exe -enable`. Alternatively, enable it through the Windows 'Ease of Access Center'.","message":"The Java Access Bridge must be explicitly enabled in your Windows environment for the wrapper to function. This is a one-time setup step for the Java installation you are targeting.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement a background thread that continuously calls Windows API functions like `GetMessageW`, `TranslateMessage`, and `DispatchMessageW` to pump messages. Initialize `JavaAccessBridgeWrapper` within this same thread. The quickstart example demonstrates this pattern.","message":"The `JavaAccessBridgeWrapper` requires a Windows message pump to be running in the same thread as the JABWrapper object to properly process UI events and interact with Java applications. Failing to implement this will prevent the library from working correctly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set the environment variable `RC_JAVA_ACCESS_BRIDGE_DLL` to the absolute path of `WindowsAccessBridge-64.dll` (e.g., `C:\\Program Files\\Java\\jre<version>\\bin\\WindowsAccessBridge-64.dll`). Alternatively, pass the path directly via the `access_bridge_path` parameter during `JavaAccessBridgeWrapper` initialization.","message":"The `WindowsAccessBridge-64.dll` path might need to be explicitly specified if Java is installed in a non-standard location or if the library cannot find it automatically. This can lead to initialization failures.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For applications with many elements, consider alternative strategies or specific options if provided by higher-level frameworks using this wrapper. If `setTextContents` fails for older JREs (e.g., 1.3.x), send keystrokes instead.","message":"Interacting with Java applications can sometimes be unstable. Common issues include target applications not supporting certain callbacks/actions, or crashes when highlighting/accessing elements, especially if a screen has a very large number of elements.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}