Whatever message this page gives is out now! Go check it out!
<cfobject
class = "Java class"
type = "Java"
name = "instance name"
action = "create"
loadPaths= "path to jar"
>Attribute | Req/Opt | Default | Description |
action | Optional | create | Only the default create action, which creates the object, is supported. |
class | Required | The Java class. | |
name | Required | String; name for the instantiated component. | |
type | Required for Java | Object type. Must be java for Java and EJB objects. | |
| loadPaths | Required for Java | A path to JAR or an array of file paths that contain Java classes or JAR files. |
<cfset ret = myObj.init(arg1, arg2)><!--- Example of a Java Object, this cfobject call loads the class MyClass
but does not create an instance object. Static methods and fields
are accessible after a call to cfobject. --->
<cfobject
action = "create"
type = "java"
class = "myclass"
name = "myobj">
<!---- Example of an EJB - The cfobject tag creates the Weblogic Environment
object, which is used to get InitialContext. The context object is
used to look up the EJBHome interface. The call to Create() results
in getting an instance of stateless session EJB. --->
<cfobject
action = "create"
type = "java"
class = "weblogic/jndi/Environment"
name = "wlEnv">
<cfset ctx = wlEnv.getInitialContext()>
<cfset ejbHome = ctx.lookup("statelessSession.TraderHome")>
<cfset trader = ejbHome.Create()>
<cfset value = trader.shareValue(20, 55.45)>
<cfoutput>
Share value = #value#
</cfoutput>
<cfset value = trader.remove()>public class Book {
private String title;
public Book(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
}<cfscript>
path="#expandPath(".")#\MyApp.jar"
</cfscript>
<cfobject type="java" class="Book" name="obj" loadPaths="#["#ExpandPath(".")#"]#">
<cfset initObj = obj.init("ColdFusion Programming!!")>
<cfoutput>#initObj.getTitle()#</cfoutput><cfobject type="java" class="com.myapp.Test" name="obj" loadPaths="#["#ExpandPath(".")#"]#">
<cfoutput>#obj.getMessage()#</cfoutput><cfobject type="java" class="Test" name="obj" loadPaths="#["#ExpandPath(".")#"]#">
<cfoutput>#obj.getMessage()#</cfoutput>
<cfcatch>
<cfset errorMsg = "Error message: #cfcatch.message#">
<cfoutput>#cfcatch.message#</cfoutput>
</cfcatch>
</cftry>
<cfset error_msg = "The getMessage method was not found.">