My Own Hello World Java Class For ColdFusion

Posted October 9, 2006 at 1:53 PM by Ben Nadel

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



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 »
11,238 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 A Comment

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.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 21, 2013 at 7:46 PM
Using Plupload For Drag & Drop File Uploads In ColdFusion
No luck. At least I have uncovered the cause, URLScan 3.1. Here is what I see in the IIS log when a file is over 30mb. 2013-05-21 23:29:05 10.105.45.128 GET /plupload/assets/jquery/jquery-1.8. ... read »
May 21, 2013 at 6:12 PM
Using Plupload For Drag & Drop File Uploads In ColdFusion
Ben, I did not see you after Pete Freitag's Lockdown session at cfObjective but he said that IIS sets file size limits at 30MB by default which just happened to be the threshold for file size when ... read »
May 21, 2013 at 11:51 AM
Ask Ben: Parsing Very Large XML Documents In ColdFusion
Looking at my first ever XML document that I have to parse and put into MS SQL 2000 with CF8. I get it to list the desired Field name, many times over, and have a long list of this field name displa ... read »
May 21, 2013 at 9:25 AM
Turning Off and On Identity Column in SQL Server
you are awesome..i am lucky to get this blog between such a garbage one....Thanks, Prashant ... read »
May 20, 2013 at 4:38 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, Your confusion is well founded, since this is a very confusing features. In fact, it ONLY works if you use array notation. Meaning, that this: arrayToList( query[ "columnName" ] ) ... read »
May 20, 2013 at 4:34 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
I was thinking chicken and the egg, I wouldn't have expected it to work in the valuelist going in I guess. Maybe I just need a beer, long day :) ... read »
May 20, 2013 at 4:29 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, That's if you're trying to reference a specific row. In this case, we're trying to reference the entire query column as one cohesive value. So, you are correct that if you wanted to output a ... read »
May 20, 2013 at 4:24 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
I thought when you used array notation to reference queries you always had to have the row or it would throw a similar error as well? ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools