AdobeStock_455007340

Accessing Java Properties

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









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:


#p["java.class.path"]#

But this won’t:


#p.java.class.path#

12 responses to “Accessing Java Properties”

  1. Ben Nadel Avatar
    Ben Nadel

    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?

  2. Ben Forta Avatar
    Ben Forta

    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. Ben Nadel Avatar
    Ben Nadel

    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 Forta Avatar
    Ben Forta

    Ben, I guess that would depend on the object. But I think you’re safe with that one.
    — Ben

  5. Ben Nadel Avatar
    Ben Nadel

    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 🙂

  6. Ben Forta Avatar
    Ben Forta

    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

  7. Ben Nadel Avatar
    Ben Nadel

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

  8. Ben Forta Avatar
    Ben Forta

    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

  9. Ben Nadel Avatar
    Ben Nadel

    Sweeeeeet. Thanks for all the clarification.

  10. Red sea real estate Avatar
    Red sea real estate

    I read this article and I just to say thanks
    Red sea real estate
    datamaster@mysharm-el-sheikh.com
    http://www.mysharm-el-sheikh.com

  11. sharm el sheikh investments Avatar
    sharm el sheikh investments

    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

  12. celebrity news Avatar
    celebrity news

    Absolutely right comments means suggestion of some words but some people write a article bigger than the orignal
    post.

Leave a Reply