CreateObject
Creates a new object representation according to the {@code type} and {@code className} arguments.
Available types are:
class/component - Resolves a BoxLang class reference (Default if not used)
java - Resolves a Java class reference
webservice - Creates a SOAP web service client from a WSDL URL
{anything} - Passes the request to the {@code BoxEvent.ON_CREATEOBJECT_REQUEST} event for further processing
If the type requested is not supported, then it passes to an interception call to the {@code BoxEvent.ON_CREATEOBJECT_REQUEST} event, so any listeners can contribute to the object creation request (if any). If there are no listeners, an exception is thrown.
You can also target an explicit class from a loaded BoxLang module by using the {@code @moduleName} suffix. Example: {@code createObject( 'class', 'class.name.path@module' )}
Modern BoxLang code can also construct BoxLang and Java classes with {@code new ClassName( args )}, by calling {@code ClassName.init( args )} on an imported class reference, or by invoking the class reference directly as {@code ClassName( args )}. {@code createObject()} remains useful for dynamic class names, legacy compatibility, custom creation types, and interception-driven creation workflows.
The properties is an optional argument that can be used to pass to the object creation process according to the type.
class/component - The properties are not used
java - The properties can be a single or an array of absolute path(s) to a directory containing Jars/Classes, or absolute path(s) to specific Jars/Classes to classload
webservice - The properties are not used
{anything} - The properties can be any object that the listener can use to create the object
IMPORTANT: For class/component types, this returns a class reference and does NOT call the class constructor automatically. For an initialized instance, call {@code init()} on the returned object, use {@code new ClassName( args )}, or invoke an imported class reference as {@code ClassName( args )}. For webservice type, a fully configured SoapClient is returned ready for method invocation.
Method Signature
Arguments
type
string
false
The type of object to create: java, class (component), webservice, or any other type
class
className
string
false
For java/class types: a fully qualified class name. For webservice type: the WSDL URL.
properties
any
false
Depending on the type, this can be used to pass additional properties to the object creation process
externalOnly
boolean
false
classloader
any
false
Optional class loader to use when loading Java classes. Only applicable for type="java".
Examples
Create a BX / Component Instance
createObject Component
Create a SOAP WebService Instance
createObject WebService
Create a java class with specified bundle and version
createObject filesystem
Additional Examples
Related
Last updated
Was this helpful?
