Whatever message this page gives is out now! Go check it out!

CreateObject: Java or EJB object

Last update:
May 18, 2026

Description

The CreateObject function can create a Java object, and, by extension, an EJB object.

Returns

A Java object.

Function syntax

CreateObject(type, class, loadPaths)

History

  • ColdFusion (2025 release): Added the parameter loadPaths.

Parameters

Parameter
Description
type
Type of object to create.
  • com
  • corba
  • java
  • component
  • webservice The default value of type is component.
class
A Java class name
loadPathsA path to JAR or an array of file paths that contain Java classes or JAR files.

Usage

Any Java class available in the class path that is specified in the ColdFusion Administrator can be loaded and used from ColdFusion with the CreateObject function.To access Java methods and fields:
  1. Call the CreateObject function or the cfobject tag to load the class.
  2. Use the initmethod, with appropriate arguments, to call an instance of the class. For example:
<cfset ret = myObj.init(arg1, arg2)>
Note:
For ColdFusion (2021 release) and later, use the following syntax:
  • createObject("java", "org.apache.poi.xssf.usermodel.XSSFWorkbook","jarname", "jar_version"). You can get the values for jarname and jar_version from the file, <cfroot>/bundles/bundlesdependency.json.
For example, createObject("java", "org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidation","poi", "4.1.2")
Tip:
When instantiating classes from underlying OEM libraries, it's suggested to use additional arguments specifying the library's version number.
This may help resolve issues resulting from differences in the classes across different versions of the libraries.
For ColdFusion 2021 and above, Adobe recommends using the dependencies file mapped in the ColdFusion Administrator.
Calling a public method on the object without first calling the "init" method invokes a static method. Arguments and return values can be any Java type (simple, array, object). If strings are passed as arguments, ColdFusion does the conversions; if strings are received as return values, ColdFusion does no conversion.Overloaded methods are supported if the number of arguments is different. Future enhancements will let you use cast functions that allow method signatures to be built more accurately.

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page