Skip to main content

How to launch or connect to Java Application using Java driver

How to launch or connect to Java Application using Java driver

Introduction

Currently Java driver supports a number of launch modes for target application

Each of them has its own specifics so let's take a closer look

Starting new java application

Launch from JAR

When launching target application from jar, LaunchMode.EXECUTABLE_JAR must be passed as first argument and the path to application jar as second

jDriver.get(JavaDriver.LaunchMode.EXECUTABLE_JAR, "D:\\path\\to\\swing-application.jar");

By default, easy-rpa-java-agent will be used to communicate with the launched application.

If application is a JavaFX application , additional input parameter should be provided specifying the type of the application that will be run - FX_APPLICATION . Then easy-rpa-javafx-agent will be used to communicate with the launched application

jDriver.get(JavaDriver.LaunchMode.EXECUTABLE_JAR, JavaDriver.LaunchType.FX_APPLICATION,	"D:\\path\\to\\javafx-application.jar");

Launch from JNLP

JNLP is deprecated since Java 9 and removed since 11. Current platform does not support java 8 anymore, use platform version 2.9.1.

Launch from Command Line

Java driver is also capable to start java application from command line. To do so, simply pass LaunchMode.COMMAND_LINE and path to command line script to driver.get method

jDriver.get(JavaDriver.LaunchMode.COMMAND_LINE, "D:\\run-application.bat");

Attach to running java application

Java driver offers capability to attach to already running java application provided starting a new application instance simultaneously with driver is not an option.

In attach scenario either window title identifier (applicable only on WINDOWS nodes) or command line identifier (applicable on both WINDOWS and LINUX nodes) is to be provided - that will allow driver resolve PID of application process on the fly.

The search with the provided identifier will be done using the following logic:

  • the match is positive if either window title or process command line contain provided identifier
  • the matching is case-insensitive
At the moment attaching to a running JavaFX desktop application running on a LINUX node is not supported.

Lets look at the Swing Desktop App that emulates login process.

The window title is Login. Let's pass it to driver.get method together with LaunchMode.JAVA_ATTACH

jDriver.get(JavaDriver.LaunchMode.JAVA_ATTACH, "login");

If application is a JavaFX application , additional input parameter should be provided specifying the type of the application that will be run - FX_APPLICATION . Then easy-rpa-javafx-agent will be used to communicate with the launched application

jDriver.get(JavaDriver.LaunchMode.JAVA_ATTACH, JavaDriver.LaunchType.FX_APPLICATION,	"login");

NOTE Make sure the desktop app allows java.desktop/sun.awt access for all unnamed modules. That can be achieved by using the '--add-opens' JVM option like in the example below:

java --add-opens=java.desktop/sun.awt=ALL-UNNAMED -jar desktop_app.jar