Pete Freitag Pete Freitag

Getting Java System Properties in ColdFusion

Published on October 29, 2004
By Pete Freitag
coldfusionjava

A while back I wrote some CFML code to dump the Java System Properties, the code went something like this:

<cfset system = CreateObject("java", "java.lang.System")>
<!--- properties is a java.util.Properties object --->
<cfset properties = system.getProperties()>

 <!--- propNames is a java.util.Enumeration --->
<cfset propNames = properties.propertyNames()>


<cfoutput>
 <cfloop condition="propNames.hasMoreElements()">
	<cfset propName = propNames.nextElement()>
	<strong>#propName#</strong> = #system.getProperty(propName)#<br /> 
 </cfloop>
</cfoutput>

That works (the code didn't work in until CFMX 6.1, see this post), but I realized today as I wanted to display the results in a table much like the way CFDUMP works - that a java.util.Properties object is a java.util.Dictionary, and a ColdFusion structure is a Dictionary so I can probably CFDUMP a Properties object. And you can infact CFDUMP a Properties object or any Hashtable, and it will output the values in a table just like a structure. So now I can dump the java system properties in a table with only two lines of code:

<cfset system = CreateObject("java", "java.lang.System")>
<cfdump var="#system.getProperties()#">

Getting Java System Properties in ColdFusion was first published on October 29, 2004.

FuseGuard Web App Firewall for ColdFusion

The FuseGuard Web Application Firewall for ColdFusion & CFML is a high performance, customizable engine that blocks various attacks against your ColdFusion applications.

CFBreak
The weekly newsletter for the CFML Community


Comments

Actually you can do this in just one line if you really want to:

<cfdump var="#CreateObject("java", "java.lang.System").getProperties()#">
by Pete Freitag on 10/29/2004 at 2:55:58 PM UTC
The static method setProperty("jdbc.drivers","org.hsqldb.jdbcDriver")

This works however the changes don't stay around. Is there anyway to edit and get CF to see the changes? Thanks D
by Daniel Plesse on 10/28/2005 at 10:04:14 PM UTC