Leveraging Java in Your ColdFusion Applications

There are four basic ways to use Java with ColdFusion:

  1. CFX tags
  2. JSP tags
  3. Using CFOBJECT or createObject() to accesses custom classes in your classpath
  4. Direct embedding (usually using CFScript)

CFX tags have a very straightforward interface. You simply implement a function called processRequest contained in the interface com.allaire.cfx.CustomTag, and work with the Request and Response objects that get passed in. CFX tags are the easiest way to implement ColdFusion tags in Java. The JSP custom tag interface is much more complex and flexible, allowing you to respond to very specific tag parsing events, nest tags, and work with body content. Using the CFOBJECT tag or createObject function is as easy or difficult or as the APIs you are accessing, while the simplest way to work with Java in ColdFusion is probably to embed it directly, typically using CFScript.

How often do you find yourself using Java in your ColdFusion applications? What do you typically use it for, or what have you used it for in the past? Finally, which of the techniques above do you typically use, and why?

13 Responses to Leveraging Java in Your ColdFusion Applications

  1. Todd says:

    I find myself exploring more and more with #3 (using createObject()).

  2. Massimo Foti says:

    I am using Java in CFML more and more. I started with things than in CF 5 required COM objects or external programs, like image manipulation. Now I am also using it for advanced XML/XSL/DOM stuff and file I/O (including zip files).I never felt the need to use CFX and I only evaluated a few JSP tags, mainly for testingThe italian CFUG website has a section dedicated to Java/CFML integration:http://www.cfmentor.com/code/index.cfm?action=ls_script&cat=14

  3. paulH says:

    i use createObject w/cfscript for i18n functions for locales that cf doesn’t support, interface with 3rd party apps (like arcIMS via its java connector, inetAddressLocator, etc.) or whenever i need something thats faster or easier in java. daily, i guess.you can directly embed java in cfscript? can you post some examples?

  4. Sam says:

    I find myself using createObject a lot in response to webforum questions, but I hardly ever use Java in our boring production apps. The only production instance is a CFX tag for spell checker.What is the difference between #3 and #4? By direct embedding do you mean the forName() thing? I’ve done that once when we needed to upload files on a shared host that had cffile disabled, but would have rather the host enabled cffile and just implemented directory security properly.

  5. paulH says:

    reflection’s a bear for anything complicated.

  6. Christian Cantrell says:

    I just added the word “custom” to #3 to make it clearer. What I mean is that you don’t have to use the CustomTag or the JSP custom tag interfaces to use Java from CF. You can just write any types of objects you want, and as long as they are in your classpath, you can instantiate them using CFOBJECT or createObject. #4 refers to using the JDK directly from ColdFusion (which is essentially using introspection) without writing your own Java files.Christian

  7. I used to do a lot of Java CFX tags, but have more recently dropped that in favor of using createObject in CFSCRIPT. I love the Java support in CFMX, and I feel like I have so much more unhindered access to Java assets in CFMX than I ever have.

  8. Tarantor says:

    … and I have just bought a new book “Java for ColdFusion Developers” from Eben Hewitt and it seems not bad. :-)And I am just converting my image tools into Java based solutions. As you know CFX_Image etc. sucks and I think JAI or other opportunities rocks! 🙂

  9. Jade says:

    Just like the previous comment, I am using Java to manipulate images and also to convert between file types (pdf, etc).I use CFScript for this, as I found it to be a lot easier than the other options. I had never used CFX tags in the past because the interface was a little limited.

  10. I guess I use #3 most with some #4. If the Java API is complex or ugly, I just wrap it up in a CFC and expose a more CF-friendly interface.BTW, I see Daine has spammed your blog too…

  11. Buy.com says:

    Just like the previous comment, I am using Java to manipulate images and also to convert between file types (pdf, etc).I use CFScript for this, as I found it to be a lot easier than the other options. I had never used CFX tags in the past because the interface was a little limited.

  12. rlash says:

    I found these blogs following links on a java image manipulation search. I am trying to find some java manipulation resources to use in CFC.Any links, resources info appreciated. I am not looking for a pricey solution but something open source that I can use.Thanks

  13. bullcatt says:

    I would like to know, when and why are the best times to use java in a cold fusion page