views:

184

answers:

5

Responders to the question know, of course, that ColdFusion is a Java EE application and can access all underlying Java classes, supports JSP custom tag libraries, etc. But what I want to know is when to write code in Java, compile it as a JAR, and reference it in CFML.

This is all in the context of a CF MVC app written in a framework like Fusebox, Mach-II, or Model-Glue.

+2  A: 

Ideally you want to build a JAR, never.

If you can get away with making java calls from cfml, do that instead, or write a cfc to handle it for you.

If there is custom java functionality you need to build that does not yet exist, then build a JAR.

An example for me was generating barcodes in Coldfusion. I could have written a java wrapper for the excellent Barbeque package. Instead I started a CFC and then stumbled across one that had already been built.

The wonderful thing about Java is very few problems are original or unique. Chances our the problem has already been solved. Java has an incredible number of libraries alrady built for it.

I may have misunderstood something said.

Jas Panesar
+5  A: 

There are three obvious reasons I can see to jump into Java:

  • When there is existing Java functionality that does what you want (don't re-invent the wheel).

  • When Java can do something better (or differently) than CF does.

  • If you have identified a performance issue that using Java can solve.

In general though, I wouldn't write new Java code to use in CF - I'd look for existing classes that are already more proven.

Peter Boughton
+2  A: 

I have thought for a while that for a large CF app you should start to build from the back, forward in java.

I think CF is very good for two things. RAD and building HTML pages. It is not a general purpose language.

If you have extensive business logic, then I recon that you should build this in java (or RAD in CFCs and then use them as a wrapper for java). The web front end is just a façade of the business logic. You may find that things like billing and stock control work better with other front ends. Having the core of the system in java allows this.

CF is an increasingly niche technology. CF developers are hard to find. While I think it is a great language, I think from a business perspective building a large app in CF is potentially money down the drain. Keeping the bulk of the app in Java lets you hire from a bigger pool of developers and future proofs much of the application.

Jeremy French
+1  A: 

We have an old CF6.1 application with java buried in it. Migrating to a newer CF version has been very painful because o the buried java.

So I say dont use your own java in a Coldfusion application.

MarkIreland
+1  A: 

The best answer is that it depends on the specifics of your situation. What's your staff's skillset in CF and in Java? Who's stronger in design and architecture? What is the code expected to do? Do you expect to do things that are easier to do in Java? Are you reusing business logic from elsewhere that's already written in Java? I wouldn't set out with the intention of breaking the code for the app in to two languages. Don't introduce complexity until it's required.

hofo