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.

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:


But this won’t:

12 thoughts

  1. 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.
    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?

  2. 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

  3. 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?

  4. 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 🙂

  5. 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

  6. 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)?

  7. 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

Leave a Reply to Ben Nadel Cancel reply