Determine which Java JRE is being used by an application running on MacOS or other Unix based systems
The other day, I thought I was having some issues with an application that was written in Java that our software team was testing some latest updates. One issue I was having was known to be an issue on a MacOS with Java 8 build 161 where a popup dialog box would not close properly. I tried to figure out what version of Java I had on my machine because I knew I had downloaded various JDKs over the last 5 years. I tried in terminal the command java -version which said I was using a very old build, however the Java Control Applet in System Preferences was saying I was using Java 8 build 161.
I updated my Java to 8 build 181 and then the application was working exactly as expected. This led me to believe that the application was using my installed version of Java JRE, instead of the bundled version that was imbedded in the software package. Which is odd, because our development team was sure that the bundled version of Java would be used and the version installed on the host would be ignored. At the time of the issue, I did not know how to confirm which version of Java the application was using. So, it was decided we would start from ground zero and wipe my hard drive clean and reinstall my MacOS.
After a clean install, I verified that I did not have Java installed. I tried the terminal command and got an error, I looked for the Java Control applet in System Preferences and I also looked in the /Library folder to see if I could find and JDK. Nothing. And then I found a very useful webpage that helped me look to see what version of the JRE was being used by the application.
First, start up the Java application in question. Next, we need to list all the running processes and get the PID for the Java Application. In terminal, type ps -ef | grep CERF
and hit enter. “CERF” is the name of the Java application I was looking for in this instance. Get the PID (the second column number) and then we will use a command to list all of the files opened by that process looking for the line items that use a JRE. In terminal type lsof -p 976 | grep jre
and the last column is the name of the file used. This should be the JRE files that are bundled with the software package, assuming that a JRE was indeed bundled with the software.
So, why bundle the JRE with the Java application. Well, many errors can be attributed to a developer using one version of Java and testing, compared to the version of Java that a user might have installed on their machine. Bundling the version of Java that is known to work with the application keeps errors down and are also easier to track. Trying to guess what version of Java a user might have can make trouble shooting errors harder. As an added benefit, if the JRE is bundled with the application, then the user does not need to install Java on their computer for the application to still work.
As an aside, I found out that the software team did update the logging function on the newest version of the beta of the Java application to output the version of Java being used by the application into a hidden log file. I checked the log and compared to the information I found in the terminal and they were a match.