Attaching to a Java application started by Eclipse

Last edited on

To attach to a Java application started by Eclipse the following two approaches are possible.

The approach described here requires the permission to adjust the JRE installation, thus it might not be suitable in a lot of case. An alternative approach is described in our blog .

The following shell script should be created. (These steps are tailored towards Linux but should be easy to adapt for other systems.)

Step 1:

Create a shell script with the following content. The path to the Squish installation should be changed as well as the path to the JRE that is used by Eclipse.

The shell script needs to be placed into the Java installation. It has to reside in the same directory as the java binary, usually inside the bin directory of the Java installation.

#!/bin/sh

/opt/squish-for-java-6.6.2/bin/startjavaaut --port=4444 /usr/lib/jvm/java-11-openjdk-amd64/bin/java "$@"
java_squish.sh

Step 2:

At Run Configurations... > JRE select Alternate JRE, but leave the JRE selection as it is.

Below in Java executable choose Alternate and enter the name of the shell script that was placed into the Java installation. Save the configuration and use it to start the AUT.

Step 3:

In the Squish IDE register an Attachable AUT at Edit > Server Settings > Manage AUTs..., for example with Name “my_attachable_aut”, Host “127.0.0.1” and Port “4444” (all without double quotes).

Step 4:

Insert attachToApplication() into an existing test script instead of startApplication():

def main():
    #startApplication("my_aut")
    attachToApplication("my_attachable_aut")
test.py

Or use Run > Launch AUT to connect to the AUT that is launched by Eclipse.