Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at cf.Objective() 2012 (Minneapolis, MN) with:

My Own Hello World Java Class For ColdFusion

By Ben Nadel on
Tags: ColdFusion

I downloaded the Java 5 SDK and tried to create a Java class. It compiled fine, but when I tried to run is using the URLClassLoader, I got the ColdFusion error:

HelloWorld (Unsupported major.minor version 49.0) null

Apparently, ColdFusion MX 7 is still running on the Java VM 1.4.2 (thanks CF-Talk!). I downloaded the Java 1.4.2 SDK from Sun and with some help from my Java-knowing co-worker, David Stamm, I easily created my first Hello World Java Class:

  • public class HelloWorld {
  •  
  • public HelloWorld(){
  • // Constructor code.
  • }
  •  
  • public java.lang.String SayHello(){
  • return(
  • "Hello You Beautiful World, You!"
  • );
  • }
  •  
  • }

Yeah, yeah, I know I don't need "java.lang.String", but I am learning, and that makes me feel more comfortable like a warm blanket. I loaded this using the URLClassLoader and everything worked super nice. Now that I know that I can do this, it's time to get some crazy experimenation going.... more on that to come :D

Tweet This Great article by @BenNadel - My Own Hello World Java Class For ColdFusion Thanks my man — you rock the party that rocks the body!


Reader Comments

Yes, I realized the same after writing some date/time, timezone, and locale classes at my work for our ColdFusion devs.

Reply to this Comment

The problem I'm having with URLClassLoader is if my Java code reference other Java classes (that are part of the standard Java library) then even if those classes are in the same directory, they don't get imported.

Apparently, the Java VM is still looking in the class path set by CF to find an classes it needs to import.

So if you are going to use Java and use classes that import classes that are not part of the standard Java install on CF then URLClassLoader is not going to work for you.

Reply to this Comment

Bruce,

I have not even gotten there yet :) Right now, I am trying to pass in a ColdFusion component and call methods on it. Apparently that is a real pain. I am not 100% familiar with how classes are typed. ColdFusion components are of type coldfusion.runtime.TemplateProxy and that doesn't seem to allow me to call methods directly. Furthermore, I can't define any variables of that type since I don't have access to that as far as I know (via Import... I am not on a CF machine).

I am working through this slowly, but it is a hard, up hill battle.

Reply to this Comment

Hey Ben,

Using java classes in cold fusion is a fantastic solution to Oh so many problems and overcomes any limitation of CF i've encountered. I've found it very easy to load classes through CreateObject. You do have to specify your class path which isn't too much of a hassle.

I use Eclipse IDE for java which allows me to set the compile version to 1.4, necessary for CFMX7. It also allows me to import external JARs and jres. I imported the coldfusion.jar and imagine the wealth of knowledge as you can peruse the coldfusion framework in its package hierarchy, although source isn't included you can see the public methods and properties as well as the super class that the folks from Allaire extended from.

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.