pf » Getting Java System Properties in ColdFusion

Getting Java System Properties in ColdFusion

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

This entry was:

Trackback Address: 174/46A472584E3F0D842794090D737AEE02
On 10/29/2004 at 2:55:58 PM MDT Pete Freitag wrote:
1
Actually you can do this in just one line if you really want to:

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

On 10/28/2005 at 10:04:14 PM MDT Daniel Plesse wrote:
2
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

On 09/06/2006 at 7:29:21 PM MDT ral wrote:
3
Hi, When I run the code, I get "System" in the user.name property instead of my actual login name...any idea?




  



Spell Checker by Foundeo





Subscribe to my RSS Feed: solosub RSS
Tags