Tuesday, January 15, 2008

Determining ColdFusion's class path and user account programatically

Two questions that come up frequently on blogs or forums is how to check ColdFusion's class path and how to determine the user account used by the ColdFusion service. The usual answer is to check the jvm.config file (classpath), and the windows o/s control panel > services (user account).

While working with the java.lang.System class today, I stumbled across two properties that appear to reveal that information. Now you may already be familiar with this. But I myself am still slightly incredulous I never noticed it before.

Note, property names are case sensitive!


<!--- cfSearching: display the CF classpath and user account name --->
<cfset sys = createObject("java", "java.lang.System")>

<!--- cfSearching: display the CF classpath and user account name --->
<cfoutput>
<b>user.name</b> = #sys.getProperty("user.name", "not found")#<hr>
<b>coldfusion.classPath</b> = #sys.getProperty("coldfusion.classPath")#<br>
</cfoutput>


To display all System properties


<!--- cfSearching: show all properties --->
<cfset prop = createObject("java", "java.lang.System").getProperties()>
<cfdump var="#prop#">


This one will definitely be added to my utility library.

1 comments:

Anonymous,  February 8, 2009 at 5:56 AM  

Sweet!... Very useful. I can run this against my hosting account and know exactly how i'm setup.

Cheers

The Job Fool

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Header image adapted from atomicjeep