My Own Hello World Java Class For ColdFusion

Posted October 9, 2006 at 1:53 PM

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:

 Launch code in new window » Download code as text file »

  • 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

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Other Searches  |  Print Page




Reader Comments

Oct 9, 2006 at 5:03 PM // reply »
19 Comments

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


Oct 9, 2006 at 5:10 PM // reply »
3 Comments

You the man.....


Oct 9, 2006 at 5:55 PM // reply »
3 Comments

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.


Oct 9, 2006 at 5:56 PM // reply »
3 Comments

Above should be ARE NOT part of the standard Java library of classes...


Oct 9, 2006 at 6:06 PM // reply »
7,572 Comments

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.


Aug 16, 2007 at 4:26 PM // reply »
4 Comments

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.


Post Comment  |  Ask Ben

Recent Blog Comments
Mar 20, 2010 at 12:07 PM
Drawing On The iPhone Canvas With jQuery And ColdFusion
Simply awesome. Saved my day. ... read »
Mar 20, 2010 at 9:00 AM
Building A Fixed-Position Bottom Menu Bar (ala FaceBook)
I would like to say thx for an easy way to create a bottom bar. I do have a ?. Is it possible to center the bar if i want to resize it to ex 85%. Regards Offenbach ... read »
Mar 19, 2010 at 7:26 PM
MySQL 3/4 - com.mysql.jdbc.Driver And allowMultiQueries=true
Thank you very much for this post. Adding allowMultiQueries="true" in context.xml didn't help until I added it to url as allowMultiQueries=true Good idea is to use prepared statements and it will he ... read »
Jim
Mar 19, 2010 at 4:49 PM
Nobody Puts Baby In The Corner!
Wow. This is like suddenly finding a support group for your secret shame. I'm not alone! I always liked this movie, even though it is extremely cheesy. I just wish Jennifer Grey hadn't gotten the ... read »
Mar 19, 2010 at 4:47 PM
Application.cfc OnRequest() Method Affects OnError() Arguments
@Jason and @Ben, I've been doing some CF9 refactoring on our systems and noticed an odd occurrence with onError as well. Found a way to work around my problem, but what I saw was... Background: Our ... read »
Jim
Mar 19, 2010 at 4:44 PM
Shoot 'Em Up Starring Clive Owen And Paul Giamatti
I actually enjoyed this movie quite a lot. It was different, certainly, but I think they were going for more of a Quentin Tarentino-"wow, that was weird"-vibe than an actual spoof. Once I realize ... read »
Mar 19, 2010 at 4:34 PM
An Intensive Exploration Of jQuery With Ben Nadel (Video Presentation)
Hey I guess the video is down. Is there anyway you can upload to youtube or vimeo or some other service? Greatly appreciated. ... read »
Mar 19, 2010 at 4:24 PM
ColdFusion CFPOP - My First Look
@Ben Thanks for the follow up! The root of the problem had to do with being able to trace bounced emails to specific records in a DB table. Let's say you run an email campaign and you get 1,000 bou ... read »