Hooking via JVM Parameters

Last edited on

Overview

By default Squish hooks into Java applications by providing a customized Java VM shared library, the Squish Java VM.

The Squish Java VM (in SQUISHDIR\bin\jvm.dll on Windows) is used for hooking Java applications transparently with Eclipse-based applications and for applications which are being run via java.exe, javaw.exe, etc.

If this hooking method does not work (because the launcher does not offer an option to specify the Squish Java VM directory (for Eclipse the -vm option is used) hooking can usually also be managed by providing additional Java VM parameters to the custom launcher.

For <code>java</code> or <code>java.exe</code>

For applications starting java or java.exe via scripts or batch files you can try to get hooking to work “manually”. In the script or batch file that runs java (or java.exe on Windows) do the following:

Step 1 - Unset the environment variables JDK_ALTERNATE_VM and _JAVA_OPTIONS before executing Java

For Windows:

set JDK_ALTERNATE_VM=
set _JAVA_OPTIONS=

For bash shells on Unix systems:

unset JDK_ALTERNATE_VM
unset _JAVA_OPTIONS

Step 2 - Modify how Java is invoked

If the invocation looks like this:

java <all_the_other_parameters>

On Windows, change it to:

java "%SQUISH_JAVA_DEF_1%" "%SQUISH_JAVA_DEF_2%" "%SQUISH_JAVA_DEF_3%" "%SQUISH_JAVA_DEF_4%" "%SQUISH_JAVA_DEF_5%" "%SQUISH_JAVA_DEF_6%" "-Dsquish.bcel=%SQUISH_PREFIX%\lib\bcel.jar" <all_the_other_parameters>

And on Unix systems, change it to:

java "$SQUISH_JAVA_DEF_1" "$SQUISH_JAVA_DEF_2" "$SQUISH_JAVA_DEF_3" "$SQUISH_JAVA_DEF_4" "$SQUISH_JAVA_DEF_5" "$SQUISH_JAVA_DEF_6" "-Dsquish.bcel=$SQUISH_PREFIX/lib/bcel.jar" <all_the_other_parameters>

For Eclipse or launchers created by Eclipse

Create a batch file or shell script similar to this:

Windows batch file:

set JDK_ALTERNATE_VM=
set _JAVA_OPTIONS=
cd "C:\Program Files\MyApp"
eclipse -vmargs "%SQUISH_JAVA_DEF_1%" "%SQUISH_JAVA_DEF_2%" "%SQUISH_JAVA_DEF_3%" "%SQUISH_JAVA_DEF_4%" "%SQUISH_JAVA_DEF_5%" "%SQUISH_JAVA_DEF_6%" "-Dsquish.bcel=%SQUISH_PREFIX%\lib\bcel.jar"

Unix shell script:

unset JDK_ALTERNATE_VM
unset _JAVA_OPTIONS
cd "/opt/MyApp"
eclipse -vmargs "$SQUISH_JAVA_DEF_1" "$SQUISH_JAVA_DEF_2" "$SQUISH_JAVA_DEF_3" "$SQUISH_JAVA_DEF_4" "$SQUISH_JAVA_DEF_5" "$SQUISH_JAVA_DEF_6" "-Dsquish.bcel=$SQUISH_PREFIX/lib/bcel.jar"

You can also provide these -vmargs in the eclipse.ini file (or in the application’s own myapp.ini file), but some people consider this to be intrusive.

For launchers created by NetBeans and install4j

Step 1: Create a batch file or script

On Windows:

Create a file called myapp_squish.bat and save it in the same directory as the .exe file of your application (e.g. “C:\Program Files\MyApp\bin\myapp_squish.bat”.

The file should have the following contents:

myapp.exe "-J%SQUISH_JAVA_DEF_1%" "-J%SQUISH_JAVA_DEF_2%" "-J%SQUISH_JAVA_DEF_3%" "-J%SQUISH_JAVA_DEF_4%" "-J%SQUISH_JAVA_DEF_5%" "-J%SQUISH_JAVA_DEF_6%" "-J-Dsquish.bcel=%SQUISH_PREFIX%\lib\bcel.jar"

Of course you need to replace “myapp” with the actual file name that starts your application.

On Unix:

Create a file called myapp_squish.sh and save it in the same directory as the file that starts your application (e.g. “\opt\myapp\bin\myapp_squish.sh”.

The file should have the following contents:

myapp "-J$SQUISH_JAVA_DEF_1" "-J$SQUISH_JAVA_DEF_2" "-J$SQUISH_JAVA_DEF_3" "-J$SQUISH_JAVA_DEF_4" "-J$SQUISH_JAVA_DEF_5" "-J$SQUISH_JAVA_DEF_6" "-Dsquish.bcel=$SQUISH_PREFIX/lib/bcel.jar"

Of course you need to replace “myapp” with the actual file name that starts your application.

Step 2: Set the AUT to the batch file or shell script

In the test suite’s settings set myapp_squish.bat or myapp_squish.sh as the Application Under Test.

In addition, make sure that you run Squish’s setup program (SQUISHDIR/setup), and point it to the folder of the JRE that your application is using.

When hooking still fails

When hooking your application still fails please check which JRE your application uses (see Finding the JRE that executes a Java application ), run Squish’s setup program again and specify exactly that JRE in it.

If hooking still fails please contact froglogic support and attach the .bat file/shell script as well as the file server.ini (Windows: %appdata%\froglogic\Squish\ver1; Unix: $HOME/.squish/ver1) to your email.