2
votes

I am using ColdFusion 9.1.0

I am trying to create a java object using CFSCRIPT and I just can't get the right combination of stuff to work.

This works perfectly:

<cfobject action="create" type="Java" class="CyberSource" name="auth">
<cfset VARIABLES.ResponseString = auth.runTransaction(LOCAL.PropsFile,LOCAL.MyXML)>

When I do this, I get an error:

LOCAL.MyObject = createObject("java", "CyberSource.auth");
LOCAL.ResponseString = auth.runTransaction(LOCAL.PropsFile,LOCAL.MyXML);

This is the error I get:

Object Instantiation Exception.
Class not found: CyberSource.auth

The object is an external piece of code available to ColdFusion. I don't see what the problem is. Do you?

2

2 Answers

7
votes

The classname is CyberSource and the variable you are trying to assign the instance to is "auth" in your tagbased approach. You mixed it up with "MyObject".

LOCAL.auth = createObject("java", "CyberSource");
LOCAL.ResponseString = LOCAL.auth.runTransaction(LOCAL.PropsFile,LOCAL.MyXML);

This should work.

2
votes

One thing to be aware of.

The java class names are case sensitive!

// Fail
myFile = createObject( 'java', 'java.io.file' );

// Win!
myFile = createObject( 'java', 'java.io.File' );

And to call their constructor, use .init() eg.

myFile = createObject( 'java', 'java.io.File' ).init( '/Users/Mike/Dev/Test' );