Is Java supported in CFMX?

The question of what is supported Java usage in CFMX came up on a mailing list today. When is Java fully supported and when is it not? Can we expect our applications to continue to work in future versions of ColdFusion if we take full advantage of Java? What about the wonderful ColdFusion internal classes?

Here’s my $0.02…

If you use a java object that is available in your classpath and that
doesn’t rely on any intenral behavior of CF then it’s fully supported. For
example, you can use Axis or Xerces to your heart’s content separate from CF
(i.e., you do all the Java instantiation with cfml/cfscript and are not tapping
into CF internal behavior). This code will continue to work even if CF
drops Axis or Xerces because you can add them to your classpath. It should
even work in CF5 if you add the objects to your classpath.

Here’s an example of fully supported Java:

Unzip a file in CFMX with java.util.zip

It uses a bunch of Java objects but doesn’t rely on the fact that CF uses
them.

Here’s an example of unsupported Java usage:

Access session vars from outside the session

It uses one of CF’s internal Java classes which might go away in a future
version (or might be locked down to block cross-application session
grabbing). This is also true if you use a 3rd party class like Axis that CF
is using. If you’re relying on the fact that CF uses it for your code to
work, then it’s unsupported.

And then there’s this syntax which I would consider unsupported, or at least fragile:

s = "";
c = s.getClass();
fil = c.forName("java.io.File");

This gets around the createObject security restrictions and allows you to
run any Java code on the server. It’s pretty well known but I think it’s a
security issue that will be fixed in a future version of CF or an updater.

So what does this mean if it’s supported or unsupported? Supported usually means that you can write the code and rely on it still working in the future. For the most part that’s true, supported CF code written for earlier versions of CF works in CFMX. If it doesn’t work due to a bug that’s a different issue, but the key point is it’s supposed to still work.

But supported doesn’t always mean forward compatible. For example, CFCHART was the supported and even new in CF5 but removed completely from CFMX, superceded by CFGRAPH. Anyone tried to move a Visual Basic application from VB6 to VB.NET? All the code has to change so sticking to supported techniques there bought you nothing for forward compatibility.

In my opinion it’s fine to use unsupported code in your applications and I’m going to continue to blog snippets. As long as your whole application isn’t entirely dependent on large blocks of unsupported code, changes to the code to make it compatible with a future version of CF should be minor.

The only time we’re completely against using unsupported code is with commercial components–Flash components in our case. Since we’re selling code that others will put into their applications, then we don’t want to limit ourselves to the many companies that would be against using unsupported code.

17 thoughts on “Is Java supported in CFMX?

  1. I believe your conclusions are sensible, and I agree. I would only add Java is supported (as in you want to open a ticket with Technical Support) to the extent that you are accessing Java through the documented mechanisms (cfobject, createobject, etc…), that the intended classes are in ColdFusion’s classpath (explicity or implicitly), that the object can be instantiated, and that the object can receive and return data as parameters as needed. If there is a problem in any of those areas, Technical Support can investigate them to develop solutions, workarounds, or hotfixes depending on the exact nature of the problem.

    However, if the reported problem is isolated to be in the class source, say a bug in the Java code of that class, then that is outside the scope of ColdFusion Technical Support. In that case, an issue should be taken up with the author of that Java program, be it a large vendor such as Sun or a small shop selling custom tags.

    See also:
    1)official Macromedia ColdFusion Support Policy: http://www.macromedia.com/support/programs/policies.html
    2) Corresponding blog on Talkingtree.com:
    http://www.talkingtree.com/blog/index.cfm?data=20030812#F8746761-40CA-1709-54E45DC497B29B88

  2. Steven, many thanks for the official link and your input. Also thanks for the blog link, lots of great content there–I’ve been meaning to add it to my list since CFUN.

  3. Pingback: CFMX Blog

  4. A Chicago lawyer named George successfully defends a major crime lord from charges of dealing drugs, racketeering, murder, kidnapping, and selling arms.
    As he is leaving the courtroom, an indignant old woman grabs him by the arm. “Young man, where are your Christian scruples? I believe you would defend Satan himself!”
    “I don’t know,” George says, “what has your kid done?”
    :) :) :)

  5. A cat dies and goes to Heaven. God meets him at the gate and says, ‘You’ve been a good cat all of these years. Anything you desire is yours, all you have to do is ask.’
    The cats says, ‘Well, I lived all my life with a poor family on a farm and had to sleep on hardwood floors.’ God says, ‘Say no more.’ And instantly, a fluffy pillow appears. A few days later, 6 mice are killed in a tragic accident and they go to Heaven. God meets them at the gate with the same offer that He made the cat.
    The mice said, ‘All our lives we’ve had to run. We’ve been chased by cats, dogs and even women with brooms. If we could only have a pair of roller skates, we wouldn’t have to run anymore.’ God says, ‘Say no more.’ And instantly, each mouse is fitted with a beautiful pair of tiny roller skates.
    About a week later, God decides to check and see how the cat is doing. The cat is sound asleep on his new pillow. God gently wakes him and asks,
    ‘How are you doing? Are you happy here?’
    The cat yawns and stretches and says, ‘Oh, I’ve never been happier in my life. And those Meals on Wheels you’ve been sending over are the best.
    :) :) :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>