How to launch or connect to Java Application
How to launch or connect to Java Application
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 using it's name when starting a new application instance simultaneously with driver is not possible.
To figure out the application name, start it manually and find its process id using your tool of choice.
For example here we started webutl demo from Oracle and found its PID is 14264 in Windows task manager
Next we need to start jps utility from jdk in command line to find the application name corresponding to 14264
Here we go, the application name is PluginMain
. Let's pass it to driver.get
method together with LaunchMode.JAVA_ATTACH
jDriver.get(JavaDriver.LaunchMode.JAVA_ATTACH, "PluginMain");