Confirming ColdFusion's Java version, via admin, vars, or code
Note: This blog post is from 2021. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.Have you ever wished you could confirm with 100% certainty what Java version is in use by the CF instance you are running? Or where the JVM's location is (in case you are told to modify files related to it)?
Some good news is that ColdFusion offers simple ways/variables that can show you each of these, via the admin or via CFML code. In this post, I discuss both approaches, including a simple single variable which works in CF2018 and above, a variation for those on CF2016 and earlier, as well as variations for Lucee.
Background
There can be occasions when you may be trying to solve a problem, and the question may arise of what Java (JVM, JRE, JDK) version (and update level) is in use by your CF instance. Or you may be told you should modify some file in the JVM's location (like its lib/security/cacerts). And you may THINK you know what version and location is being used by your instance of CF, but people can sometimes presume incorrectly--or they be misled by others who presume the wrong thing or who may well be misled by unexpected configuration differences.
The multiple ways you can check the Java version underlying CF
While the focus of this post is on how to find your CF version via code, it is of course not the only way (though it may be the most reliable way to know for SURE what is the version for the CF server on which your CFML code is running).
Checking the Java version via the CF or Lucee Admin
Most people know (though not everyone does) that they can find the Java version underlying their CF instance by way of the CF Admin, using either the "Settings">"Settings Summary" page or via the "system information" page (accesses via the 'i" in the top right corner of the CF Admin). Same with the Lucee Admin, which shows it on the front page.
But perhaps you don't have access to the CF or Lucee admin--or you may mistakenly look at the WRONG CF admin, if you run more than one instance of CF (as I discuss further below).
Outputting the information via code, in the template where you have a problem (that may be related to the Java version in use) is the most direct way to know for sure what JVM version is used by THAT instance where the code is running.
Checking the Java version via code in CF2018 and above: CF's server.system.properties.java struct
The easiest way to see the Java version and the jvm's directory location (in use by the CF server where the CFML code is running) is to output the following variables--found within the server scope's "system" struct, which became available as of CF2018 and above:
server.system.properties.java.home
You could of course use CFOUTPUT, CFDUMP, CFLOG or their cfscript equivalents, or whatever means you prefer for accessing/showing this variables.
<cfdump var="#server.system.properties.java.home#">
And if you wonder about still other JVM characteristics, you could of course change it to a
You may wonder why I don't propose that you dump "server.system.properties.java", as the naming of the variables above suggests it would be a struct. But it's not. Instead, things like that java.version and java.home are in fact instead keys in the server.system.properties struct, as you will see if you do that dump.
Still other keys in that struct that may be useful are:
Speaking of how these "java" properties in the server.system.properties are not a struct, users of Lucee will find that the simplified dot-notation syntax I offered above fails (at least in Lucee 5.3.7.48). But changing it only slightly (to refer to the "java." references as keynames in that struct) will work:
And FWIW, this other variation works in CF2018 and above, of course. CF has supported this array notation for key names in a struct since CF4.
I mentioned that it was CF2018 introduced the server.system struct, and those on earlier versions can't use that. But They can instead obtain the same information by calling upon Java directly from within your code:
And this code works in Lucee, as well (and of course in CF2018 and above).
Some may wonder why I didn't just offer this since it's "more universal". Well, it is, but it's not as clean and simple.
Finally, some people may even find that the ability to invoke such java objects (as in this last example) is restricted in their CF administrator via "sandbox security". (To be clear, the ability to run this previous code is NOT precluded by checking the CF Admin setting, "Disable access to internal ColdFusion Java components". That instead is about limiting not just whether ANY java objects can be invoked but instead whether certain specific Adobe-provided Java objects (typically undocumented "servicefactory") can be invoked.)
If the JVM version and/or location information turns out to be different from what you or others suspect (or from what you may argue you even "see" in the CF or Lucee Admin), there could be a number of explanations:
Again the main focus of THIS post is simply to make it easy for you to confirm WHAT JVM version you are using, so I don't want to go too far into the many potential explanations for things. But I will close with one more point, and with that I point to resources that may help you if you want to take things still farther (in understanding or resolving) JVM version issues.
If you may realize you have the wrong Java version implemented, perhaps you will have no choice but to go to the person who is responsible for your CF instance and present the evidence to them, and ask them to change things (if an updated JVM is needed.)
If you run your own CF instance, you may know that changing the JVM CF uses is relatively simple-- though things can go wrong. I have a post on the many things that can go wrong, and how to solve (or avoid) them. I also point there to resources to help you in performing the actual update. (Things are even more challenging if you may change from one major version to another--like Java 8 to Java 11. I address that in the post, as well.)
Or you may wonder what versions JVM versions are supported by the version of CF that you run. I have a (more recent) post on that, as well.
Finally, if you would rather just "clean up the mess" if things are incorrect, and/or you try to change things and run into problems, I can help with that, as I do about weekly with folks in my CF remote, online troubleshooting consulting. We can usually have the JVM version used by CF changed to a supported version, implemented correctly (and even setup to be easily reverted back) in a matter of minutes.
Again, the goal in this post was simply to show how easily you can find WHAT jvm version is used by your CF version...but the rest of the info is what typically flows from either wanting to know the version, or wanting to change it. Hope it was helpful.
A variation for Lucee
server.system.properties["java.home"]Checking the Java version via code in CF2016 and earlier: use Java's own system.getproperty method
system=createObject("java", "java.lang.System");
writeoutput(system.getproperty("java.version"));
writeoutput(system.getproperty("java.home"));
</cfscript>How this Java version information could vary from your expectations
If you decide to change your JVM version, some observations
For more content like this from Charlie Arehart:
Need more help with problems?
There are no comments for this entry.
[Add Comment]