Attaching to a Java application started by Eclipse

Last edited on

To attach to a Java application started by Eclipse the following steps can be used. (These steps are tailored towards Windows but should be easy to adapt for other systems.)

Step 1:

Start Eclipse process with additional environment variables (in cmd.exe or a .bat/batch file):

:: CHANGE THIS AS NEEDED:
set SQUISH_PREFIX=C:\users\myuser\squish-6.0.3-java-win64

:: Maybe configure this, should be a good default though:
set SQUISH_ATTACHABLE_PORT=4444

:: Do not change this:
set SQUISH_NO_CRASHHANDLER=1
set PATH=%PATH%;%SQUISH_PREFIX%\bin

:: CHANGE THIS AS NEEDED:
C:\Users\myuser\Eclipse\eclipse.exe
eclipse_java_attachable.bat

Step 2:

At Run Configurations... > Arguments > VM arguments insert this:

"-Xbootclasspath/p:${env_var:SQUISH_PREFIX}\lib\squishrt.jar" "-Dsquish.wrapper=${env_var:SQUISH_PREFIX}\bin\squishjavawrapper.dll" "-javaagent:${env_var:SQUISH_PREFIX}\lib\squishagent.jar=${env_var:SQUISH_PREFIX}\lib" "-Xverify:none" "-Dsquish.tmpdir=$env_var:{USERPROFILE}/AppData/Local/Temp/frogtemp" "-DSQUISH_LOG_HOOKUP=1" "-Dsquish.bcel=${env_var:SQUISH_PREFIX}\lib\bcel.jar" "-Djava.security.policy=file:${env_var:USERPROFILE}/AppData/Local/Temp/frogtemp/squish.policy"

Step 3:

Start Eclipse via eclipse_java_attachable.bat, use Run Configurations... to execute your Java application. It should then start in attachable mode automatically. (You may see the Windows firewall asking for permission to allow javaw.exe (or so) network access.)

Step 4:

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 5:

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

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

If you set a breakpoint on the snooze() command you can execute to that breakpoint and then inspect the application (if attaching to it succeeded).