An app I am working on needs to check the Java CLASSPATH (I am trying to return more useful errors if a call fails). The CLASSPATH is a Java property (kind of like environment variables) named java.class.path, and to obtain this value all you need to do is call getProperty() in java.lang.System. To make this simpler I through these two UDFs together, the first returns a structure of all Java properties and the second returns a specific property.
<!--- Return all Java properties --->
<cffunction name="GetJavaProperties" returntype="struct" output="no">
<cfreturn CreateObject("Java", "java.lang.System").getProperties()>
</cffunction>
<!--- Return a specific Java property --->
<cffunction name="GetJavaProperty" returntype="string" output="no">
<cfargument name="property" type="string" required="yes">
<cfreturn CreateObject("Java", "java.lang.System").getProperty(ARGUMENTS.property)>
</cffunction>
It is worth noting that to access a property with a . in its name you'll need to use struct["member"] syntax instead of struct.member. So this will work:
<cfset p=GetJavaProperties()>
<cfoutput>
#p["java.class.path"]#
</cfoutput>
But this won't:
<cfset p=GetJavaProperties()>
<cfoutput>
#p.java.class.path#
</cfoutput>
There are no comments for this entry.
[Add Comment]