CreateObject()

The CreateObject function takes different arguments depending on the value of the first argument:

CreateObject('com', class, context, serverName)
CreateObject('component', component-name)
CreateObject('corba', context, class, locale)
CreateObject('java', class [, context])
CreateObject('webservice', urltowsdl, [, portname])

Warning

In Lucee 5, this function has been deprecated in favour of the new object() syntax (reference needed). The only difference is that the new Object() syntax automatically calls the init() method. In line with our commitment to CFML, this function will never be dropped from the language and you are safe to use it going forward.

CreateObject( type=string, classname=object, context=object, delimiterOrVersion=object );

Returns: any

Argument Description
type
string, required

one of the following:

  • com: for loading a com Object
  • java: for loading a Java object
  • webservice: for loading a remote webservice
  • component: for loading a Component

Alias: componentType

classname
object, optional

the usage of this argument depend on type defined with argument "type":

  • com: Component ProgID for the object to invoke.
  • java: Java class to load
  • webservice: WSDL url to call
  • component: The CFC name; corresponds to the name of the file that defines the component

Alias: component, class

context
object, optional

the usage of this argument depend on type defined with argument "type":

  • com: not used (ignored)
  • java: classpath used to load the defined class. This can be a single absolute path, or an array of absolute paths, where paths are jar files or directories containing class files.
  • webservice: a struct containing the following optional keys (username,password,proxyServer,proxyPort,proxyUser,proxyPassword)
  • component: not used (ignored)

Alias: bundleName, name, webservice, Assembly, WSPortName, thirdArg

delimiterOrVersion
object, optional

the usage of this argument depend on type defined with argument "type":

  • java: delimiter used for the classpath (default comma) or bundle version when the previous argument was a bundle name
  • webservice: not used (ignored)
  • component: not used (ignored)
  • com: not used (ignored)

Alias: delimiter, version, bundleVersion

Examples

dump( label:"CreateObject in java",  var:createObject('java','java.util.HashMap'));
dump( label:"CreateObject with init()", var:createObject('java',"java.lang.StringBuffer").init());

All these examples are all functionally identical

Except that the new Object() syntax automatically calls the init() method

dump( var=createObject("component", "org.lucee.cfml.http"), expand=false );
// but even "component" is optional for cfcs
dump( var=createObject("org.lucee.cfml.http"), expand=false );

// the modern new Object() syntax is also dynamic dump(var=new "org.lucee.cfml.http"(), expand=false); dump(var=new org.lucee.cfml.http(), expand=false);

cfc = "org.lucee.cfml.http"; dump(var=new "#cfc#"(), expand=false);

See also