Finding the JRE that executes a Java application

Last edited on

Introduction

Java applications are executed by Java runtimes/installations. Such runtimes may be bundled with the application, or they may be installed for a particular user or system-wide.

Because of these possible options, and because it helps avoid problems, it is very important to configure the exact path of the Java runtime which executes the desired application in Squish for Java.

Initially the Squish installer requests the path of the Java runtime which executes the AUT. In addition, one can configure this after installation by running SQUISH_DIR/bin/squishconfig --java=<JAVA_DIR>.

However, often it is not obvious which Java runtime is being used. (It could be one that is bundled with the application, or one of several Java installations installed for the user, or a system-wide one.) The following information can be used to determine the path of the Java runtime which is executing a particular Java application.

Determining Java Installation which executes the AUT

Unix (Linux, macOS, etc.)

On Unix the general approach is to look at the Java application's open files; these should include a library called libjvm.so or similar. This can be done by using the lsof command and grepping its results, for example:

lsof -p <java_application_process_id> | grep libjvm

Of course, to make this work you need to know the running application's process ID, but you can find that using the ps command.

$ lsof -p 7404 | grep libjvm
MyJavaApp 7404 myuser  mem    REG        8,1  4670718 16789651 /home/myuser/MyJavaApp/jre/lib/i386/client/libjvm.so

Even though these steps (and the Process Explorer application) are Windows specific, similar tools should exist for other platforms:

You will probably have to resize the "Handle or DLL" column so that you can see the complete path.

A similar approach is to browse the list of DLLs in a process yourself, as explained in Getting a list of DLLs currently loaded in a process .

Windows - Using Microsoft's ListDLLs (alternative)

The tool ListDLLs can list the DLLs (and their paths) used by a process. For example if the executing .exe is java.exe:

C:\Users\myuser>listdlls java.exe

ListDLLs v3.1 - List loaded DLLs
Copyright (C) 1997-2011 Mark Russinovich
Sysinternals - www.sysinternals.com

------------------------------------------------------------------------------
java.exe pid: 5824
Command line: java  Calculator

Base                Size      Path
0x0000000000400000  0x24000   C:\Windows\SysWOW64\java.exe
...
0x0000000076760000  0xcc000   C:\Windows\syswow64\MSCTF.dll
0x000000007c340000  0x56000   C:\Program Files (x86)\Java\jre6\bin\msvcr71.dll
0x000000006d7f0000  0x2af000  C:\Program Files (x86)\Java\jre6\bin\client\jvm.dll
...
0x000000006d7a0000  0xc000    C:\Program Files (x86)\Java\jre6\bin\verify.dll
0x000000006d320000  0x1f000   C:\Program Files (x86)\Java\jre6\bin\java.dll
0x000000006d7e0000  0xf000    C:\Program Files (x86)\Java\jre6\bin\zip.dll
0x000000006d000000  0x14c000  C:\Program Files (x86)\Java\jre6\bin\awt.dll
...
0x000000006d230000  0x4f000   C:\Program Files (x86)\Java\jre6\bin\fontmanager.dll
...
0x000000006d600000  0x13000   C:\Program Files (x86)\Java\jre6\bin\net.dll
...
0x000000006d620000  0x9000    C:\Program Files (x86)\Java\jre6\bin\nio.dll

C:\Users\myuser>

In this example, the above Java program 'Calculator' is being executed by a (supposedly) 32 bit Java runtime at C:\Program Files (x86)\Java\jre6. The Program Files (x86) path component indicates that this is likely a 32-bit Java runtime, and as such a 32-bit Squish for Java installation must likely be used.

(In the example above the target process got identified by entering the executable name "java.exe". Make sure to specify the executable name of your own application when using ListDLLs. See "listdlls /?" for further options.)

Shortcut for Eclipse/RCP based applications

To find out which Java Runtime Environment (JRE) is being used by Eclipse or an RCP based application START YOUR APPLICATION WITHOUT SQUISH and click Help | About ...:

Then click on Installation Details:

And then click on the Configuration tab:

In this example the lines...

-vm

C:\Program Files (x86)\Java\jre6\bin\client\jvm.dll

...indicate that this Eclipse instance is executed by the JRE in "C:\Program Files (x86)\Java\jre6".

Sometimes these entries are not so easy to spot. In such a case you can select and copy the entire contents of the tab to the clipboard, then paste the text into a text editor and use the editors search or find functionality to locate the "-vm" line.