> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/createobject.md).

# 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

```
CreateObject(type=[string], className=[string], properties=[any], externalOnly=[boolean], classloader=[any])
```

### Arguments

| Argument       | Type      | Required | Description                                                                                          | Default |
| -------------- | --------- | -------- | ---------------------------------------------------------------------------------------------------- | ------- |
| `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

```java
<bx:script>
	tellTimeClass = createObject( "component", "appResources.components.tellTime" );
	tellTimeClass.getLocalTime();
</bx:script>

```

### Create a SOAP WebService Instance

createObject WebService

```java
<bx:script>
	ws = createObject( "webservice", "http://www.xmethods.net/sd/2001/TemperatureService.wsdl" );
	xlatstring = ws.getTemp( zipcode="55987" );
	writeOutput( "The temperature at 55987 is " & xlatstring );
</bx:script>
      
```

### Create a java class with specified bundle and version

createObject filesystem

```java
POIFSFileSystem = createObject( "java", "org.apache.poi.poifs.filesystem.POIFSFileSystem", "apache.poi", "3.11.0" );

```

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJxLKc0t0FDISUxKzbFVci5KTSxJ9U%2FKSk0uUcjMU8hKLEtU0lEoSyyyTUaS0lBQgsqAab3SkswcPY%2FE4gzfxAIlBU0FTWuuFJzGlmeWZADNzizR0CTC6JzEvHS94JKizLx0p9K0tNQioPl6EN0gawDE8j51)

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

```

```java
dump( var=createObject( "class", "com.my.bx.class" ), expand=false );
// but even "class" is optional for bx
dump( var=createObject( "com.my.bx.class" ), expand=false );
// the modern new Object() syntax is also dynamic
dump( var=new "com.my.bx.class"(), expand=false );
dump( var=new com.my.bx.class(), expand=false );
myClass = "com.my.bx.class";
dump( var=new "#myClass#"(), expand=false );

```

## Related

* [ApplicationRestart](/boxlang-language/reference/built-in-functions/system/applicationrestart.md)
* [ApplicationStartTime](/boxlang-language/reference/built-in-functions/system/applicationstarttime.md)
* [ApplicationStop](/boxlang-language/reference/built-in-functions/system/applicationstop.md)
* [BoxAnnounce](/boxlang-language/reference/built-in-functions/system/boxannounce.md)
* [BoxAnnounceAsync](/boxlang-language/reference/built-in-functions/system/boxannounceasync.md)
* [BoxAST](/boxlang-language/reference/built-in-functions/system/boxast.md)
* [BoxModuleReload](/boxlang-language/reference/built-in-functions/system/boxmodulereload.md)
* [BoxRegisterInterceptionPoints](/boxlang-language/reference/built-in-functions/system/boxregisterinterceptionpoints.md)
* [BoxRegisterInterceptor](/boxlang-language/reference/built-in-functions/system/boxregisterinterceptor.md)
* [BoxRegisterRequestInterceptor](/boxlang-language/reference/built-in-functions/system/boxregisterrequestinterceptor.md)
* [BoxUnregisterInterceptor](/boxlang-language/reference/built-in-functions/system/boxunregisterinterceptor.md)
* [BoxUnregisterRequestInterceptor](/boxlang-language/reference/built-in-functions/system/boxunregisterrequestinterceptor.md)
* [CallStackGet](/boxlang-language/reference/built-in-functions/system/callstackget.md)
* [CreateGUID](/boxlang-language/reference/built-in-functions/system/createguid.md)
* [CreateUUID](/boxlang-language/reference/built-in-functions/system/createuuid.md)
* [DE](/boxlang-language/reference/built-in-functions/system/de.md)
* [DebugBoxContexts](/boxlang-language/reference/built-in-functions/system/debugboxcontexts.md)
* [Dump](/boxlang-language/reference/built-in-functions/system/dump.md)
* [Duplicate](/boxlang-language/reference/built-in-functions/system/duplicate.md)
* [echo](/boxlang-language/reference/built-in-functions/system/echo.md)
* [EncodeForHTML](/boxlang-language/reference/built-in-functions/system/encodeforhtml.md)
* [GetApplicationMetadata](/boxlang-language/reference/built-in-functions/system/getapplicationmetadata.md)
* [GetBaseTagData](/boxlang-language/reference/built-in-functions/system/getbasetagdata.md)
* [GetBaseTagList](/boxlang-language/reference/built-in-functions/system/getbasetaglist.md)
* [GetBaseTemplatePath](/boxlang-language/reference/built-in-functions/system/getbasetemplatepath.md)
* [GetBoxContext](/boxlang-language/reference/built-in-functions/system/getboxcontext.md)
* [GetBoxRuntime](/boxlang-language/reference/built-in-functions/system/getboxruntime.md)
* [GetBoxVersionInfo](/boxlang-language/reference/built-in-functions/system/getboxversioninfo.md)
* [GetClassMetadata](/boxlang-language/reference/built-in-functions/system/getclassmetadata.md)
* [GetComponentList](/boxlang-language/reference/built-in-functions/system/getcomponentlist.md)
* [GetContextRoot](/boxlang-language/reference/built-in-functions/system/getcontextroot.md)
* [GetCurrentTemplatePath](/boxlang-language/reference/built-in-functions/system/getcurrenttemplatepath.md)
* [GetFileFromPath](/boxlang-language/reference/built-in-functions/system/getfilefrompath.md)
* [GetFunctionCalledName](/boxlang-language/reference/built-in-functions/system/getfunctioncalledname.md)
* [GetFunctionList](/boxlang-language/reference/built-in-functions/system/getfunctionlist.md)
* [GetModuleInfo](/boxlang-language/reference/built-in-functions/system/getmoduleinfo.md)
* [GetModuleList](/boxlang-language/reference/built-in-functions/system/getmodulelist.md)
* [GetModuleTree](/boxlang-language/reference/built-in-functions/system/getmoduletree.md)
* [GetRequestClassLoader](/boxlang-language/reference/built-in-functions/system/getrequestclassloader.md)
* [GetSemver](/boxlang-language/reference/built-in-functions/system/getsemver.md)
* [GetSystemSetting](/boxlang-language/reference/built-in-functions/system/getsystemsetting.md)
* [GetTempDirectory](/boxlang-language/reference/built-in-functions/system/gettempdirectory.md)
* [GetTickCount](/boxlang-language/reference/built-in-functions/system/gettickcount.md)
* [htmlEditFormat](/boxlang-language/reference/built-in-functions/system/htmleditformat.md)
* [IIF](/boxlang-language/reference/built-in-functions/system/iif.md)
* [Invoke](/boxlang-language/reference/built-in-functions/system/invoke.md)
* [IsInstanceOf](/boxlang-language/reference/built-in-functions/system/isinstanceof.md)
* [JavaCast](/boxlang-language/reference/built-in-functions/system/javacast.md)
* [ObjectDeserialize](/boxlang-language/reference/built-in-functions/system/objectdeserialize.md)
* [ObjectSerialize](/boxlang-language/reference/built-in-functions/system/objectserialize.md)
* [PagePoolClear](/boxlang-language/reference/built-in-functions/system/pagepoolclear.md)
* [Print](/boxlang-language/reference/built-in-functions/system/print.md)
* [Println](/boxlang-language/reference/built-in-functions/system/println.md)
* [RunThreadInContext](/boxlang-language/reference/built-in-functions/system/runthreadincontext.md)
* [SessionInvalidate](/boxlang-language/reference/built-in-functions/system/sessioninvalidate.md)
* [SessionRotate](/boxlang-language/reference/built-in-functions/system/sessionrotate.md)
* [SessionStartTime](/boxlang-language/reference/built-in-functions/system/sessionstarttime.md)
* [Sleep](/boxlang-language/reference/built-in-functions/system/sleep.md)
* [SystemCacheClear](/boxlang-language/reference/built-in-functions/system/systemcacheclear.md)
* [SystemExecute](/boxlang-language/reference/built-in-functions/system/systemexecute.md)
* [SystemOutput](/boxlang-language/reference/built-in-functions/system/systemoutput.md)
* [Throw](/boxlang-language/reference/built-in-functions/system/throw.md)
* [Trace](/boxlang-language/reference/built-in-functions/system/trace.md)
* [URLDecode](/boxlang-language/reference/built-in-functions/system/urldecode.md)
* [URLEncodedFormat](/boxlang-language/reference/built-in-functions/system/urlencodedformat.md)
* [writeDump](/boxlang-language/reference/built-in-functions/system/writedump.md)
* [WriteLog](/boxlang-language/reference/built-in-functions/system/writelog.md)
* [WriteOutput](/boxlang-language/reference/built-in-functions/system/writeoutput.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/createobject.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
