Getting Java System Properties in ColdFusion

October 29, 2004

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()>

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

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()#">

1 person found this page useful, what do you think?


Actually you can do this in just one line if you really want to: <cfdump var="#CreateObject("java", "java.lang.System").getProperties()#">
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
Hi, When I run the code, I get "System" in the property instead of my actual login name...any idea?

Post a Comment


Spell Checker by Foundeo

Recent Entries


did you hack my cf?