Thursday, August 28, 2008    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Aug 2006 >>
S M T W T F S
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Search

Categories
 • Acrobat (1) [RSS]
 • Adobe (66) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (21) [RSS]
 • AIR (124) [RSS]
 • Appearances (118) [RSS]
 • Books (68) [RSS]
 • CFEclipse (14) [RSS]
 • ColdFusion (1138) [RSS]
 • Data Services (12) [RSS]
 • Flash (101) [RSS]
 • Flex (362) [RSS]
 • Home Automation (2) [RSS]
 • Jobs (91) [RSS]
 • JRun (12) [RSS]
 • Labs (27) [RSS]
 • LiveCycle (21) [RSS]
 • MAX (156) [RSS]
 • Regular Expressions (12) [RSS]
 • RIA (4) [RSS]
 • SQL (37) [RSS]
 • Stuff (503) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (135) [RSS]
 • Wireless (97) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Day : August 22, 2006 / Main
August 22, 2006

Accessing Java Properties

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>

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments
This is not 100% relavent, but I am getting more into Java under CF and I am really excited to be playing around. Just the other day I made a UDF that gets a query of Java Class methods and constructors of a ColdFusion object... it's a work in progress, all experimental, but this Java stuff is really neat. http://bennadel.com/index.cfm?dax=blog:206.view

Actually, you are probably THE guy to ask... all the Java hooks that we have, are those officially supported by ColdFusion? I know the serviceFactory used to be secret, and now its sort of advertised... does that go for all underlying, accessible java stuffs?
# Posted By Ben Nadel | 8/23/06 5:18 PM
Ben, those are two different questions. Core Java stuff is not going away, we have no plans on rebuilding CF in something other than Java, so leveraging underlying Java is perfectly safe (and highly reccomended). As for CF internals that are written in Java, well, if they are undocumented then they are not supported and may indeed change or evolve - and service factory definitley falls into that category.

--- Ben
# Posted By Ben Forta | 8/23/06 7:26 PM
Ok, I can understand stuff that is not documented... but what about stuff that is exposed via the GetMetaData() method. Are those things considered "official" or is "official" limited to what is in LiveDocs?
# Posted By Ben Nadel | 8/24/06 1:00 PM
Ben, I guess that would depend on the object. But I think you're safe with that one.

--- Ben
# Posted By Ben Forta | 8/24/06 1:05 PM
Ben,

I am pretty sure I know the answer to this one, but I just wanted to run it by you. I have discovered that if i have a String object (ex. strTest = "ben forta") then I can actually call the Java replace methods directly:

strTest.ReplaceAll( [regexp], [replacestring] )

This however is not documented (that I can find). However, it can be found via the GetMetaData() and then a few other methods calls. So, I assuming that this is NOT safe to do, but I was hoping maybe it was :)
# Posted By Ben Nadel | 8/28/06 9:02 AM
Ben, simple CF variables are in fact Java strings, so you can can safely use any String class methods on them. FYI, you can always look at #var.getClass().getName()# to see what the underlying class behind a ColdFusion variable is.

--- Ben
# Posted By Ben Forta | 8/28/06 9:08 AM
Ben,

That is very exciting... I love using the Java ReplaceAll() method :) Sweeet. And yeah, I have found some interesting stuff using thet GetClass().GetName() stuff. For instance, the underlying query object is coldfusion.sql.QueryTable and that has some cool methods like IsFirst(), IsLast(), and RemoveRows() which I would be excited to use. Do you think that is safe (and that's my final question)?
# Posted By Ben Nadel | 8/28/06 9:19 AM
Those internal query object methods are how CF works its magic (how a cfoutput over a query works, for example). I guess those could change, but I highly doubt that would happen.

--- Ben
# Posted By Ben Forta | 8/28/06 9:37 AM
Sweeeeeet. Thanks for all the clarification.
# Posted By Ben Nadel | 8/28/06 9:41 AM
I read this article and I just to say thanks

Red sea real estate
datamaster@mysharm-el-sheikh.com
www.mysharm-el-sheikh.com
# Posted By Red sea real estate | 3/1/07 10:09 AM
I think that I have to say thanks after reading an article like this!!!

Red sea real estate
info@redsearealestatesharm.com
http://www.redsearealestatesharm.com
# Posted By sharm el sheikh investments | 3/13/07 9:43 PM
Absolutely right comments means suggestion of some words but some people write a article bigger than the orignal

post.
# Posted By celebrity news | 4/25/07 3:39 AM

  © Copyright 1997-2008 Ben Forta, All Rights Reserved