Railo Tip: CreateObject('java')

January 15, 2010 · By webrat · 5 Comments

I'm actually hesitant to post this because the Railo team is actually trying to make progress on documentation and we have some new documentation policies in place. However, I know if I don't post this and people eventually find out about it, they'll wonder why they didn't know sooner. This tip pertains to Railo's createObject('java') implementation. I'm told that it has been there for awhile, but I couldn't tell you what build it came from. I'll share the code and go from there.

<cfset object = createObject('java','path.to.package.classtoinvoke','/path/to/jar/file/on/system')>

Read that line 2 or 3 times and let it sink in a little. Yes, Railo's createObject('java') has a 3rd (and 4th) argument. This is the full documentation on this from Michael is:

createObject('java',String className,String paths, String delimiter )
- 'java' (required)
- className (required) - the full class name (class and package) of the class to invoke.
- path (optional) - a list of jar files and directory that contains class files
- delimiter (optional) - delimiter used for the path list (default is comma ",")

Sean Corfield will be presenting this to the opemcfml.org advisory board, whether it gets voted on or not remains to be seen. Also, please note that I'm making Documentation/Wiki a high priority for the year 2010.

Tags: Features · Tips

5 responses so far ↓

  • 1 Matthew Lesko // Jan 17, 2010 at 7:34 PM

    Does specifying this 3rd argument effectively makes a new classloader for that object?
  • 2 Paul Klinkenberg // Jan 18, 2010 at 11:23 AM

    Can you say anything about the order in which the requested java object is searched for? Will the path(s) in the 3rd argument be searched before or after the webroot and current directory?
    Thanks for the post, you are *really* anywhere these days :-)
  • 3 Todd Rafferty // Jan 18, 2010 at 6:27 PM

    @Matthew / Paul: You should both jump on the mailing list and ask since Micha's answering questions: http://groups.google.com/group/railo/browse_thread/thread/be37e8202285317f
  • 4 Michael Offner // Jan 20, 2010 at 10:38 AM

    here a short answer to the questions:

    Does specifying this 3rd argument effectively makes a new classloader for that object?
    Yes, a java.net.URLClassLoader

    Can you say anything about the order in which the requested java object is searched for?
    In java Classloaders are organized hierarchical and a class is always searched first in the parent ClassLoader.

    Will the path(s) in the 3rd argument be searched before or after the webroot and current directory?
    the webroot and the current directory is not searched for jar or class files.
  • 5 Ryan // Feb 10, 2012 at 10:18 PM

    you might consider supporting passing a classloader as an argument also (or instead of the path). Or an object whose classloader serves as the context.

    There is an issue with using Axis stub objects (you cannot create object without some fancy syntax), unless CF has made some progress that I'm not aware of.

    http://stackoverflow.com/questions/1603261/coldfusion-wsdl-and-extended-complex-classes/

Leave a Comment

Leave this field empty: