Lucee Function Reference

createobject()

Creates and returns a reference to objects of various types including Java classes, components, web services, and COM objects.
## Type: "java"
Creates a Java object instance. As of Lucee 6.2, this supports Maven dependency management and enhanced Java settings.
```
CreateObject('java', className [, classpath|bundleName|javasettings] [, delimiter|bundleVersion])
```
You can provide Java libraries in four ways:
- Using classpath: Specify directories or JAR files
- Using OSGi bundles: Provide a bundle name and version
- Using loadPaths: Define non-OSGi JAR paths directly
- Using Maven: Define Maven artifacts via a javasettings structure
### Using Classpath
```cfml
// Using directories and JAR files with a classpath
createObject("java", "com.example.MyClass", "/path/to/libs/,/path/to/specific.jar");
// Using an array of paths
createObject("java", "com.example.MyClass", ["/path/to/libs/", "/path/to/specific.jar"]);
```
### OSGi Bundle Support
```cfml
createObject(
type: "java",
class: "org.lucee.mockup.osgi.Test",
bundleName: "lucee.mockup",
bundleVersion: "1.0.0.0"
);
```
### Maven Support (Lucee 6.2+)
```cfml
createObject(
type: "java",
class: "org.apache.commons.beanutils.BeanUtils",
javasettings: {
"maven": [
{
"groupId": "commons-beanutils",
"artifactId": "commons-beanutils",
"version": "1.9.4"
}
]
}
);
```
### Java Settings Structure
The javasettings structure can contain:
- maven: Array of Maven dependency structures (groupId, artifactId, version)
- loadPaths: Array of paths to non-OSGi JAR files or directories
- bundlePaths: Array of paths to OSGi bundle files or directories
- reloadOnChange: Boolean indicating whether to reload updated classes dynamically (default: false)
- watchInterval: Number of seconds between checks for changes (default: 60)
- watchExtensions: Array of file extensions to monitor (default: ["jar", "class"])
## Type: "component"
Creates a CFC instance without calling the init method.
```
CreateObject('component', componentName)
```
## Type: "webservice"
Creates a web service client from a WSDL.
```
CreateObject('webservice', urlToWsdl [, portName] [, options])
```
## Type: "com"
Creates a COM object (Windows only).
```
CreateObject('com', class, context, serverName)
```

Example

createobject(string type,[object classname,[object context,[object delimiterOrVersion]]]):any

Arguments

The arguments for this function are set. You can not use other arguments except the following ones.
Name Type Required Description
type string  Yes Specifies the type of object to create:
  • "java": Creates a Java object instance
  • "component": Creates a CFC without calling the init method
  • "webservice": Creates a web service client
  • "com": Creates a COM object (Windows only)  
  • classname object  No Specifies the object to create based on the type:
  • "java": Fully qualified Java class name
  • "component": CFC name (file path without .cfc extension)
  • "webservice": URL to the WSDL
  • "com": Component ProgID for the object  
  • context object  No Varies by object type:
  • "java":
    * Classpath: String list or array of paths to class files or JAR files
    * BundleName: Name of an OSGi bundle
    * JavaSettings: Structure containing Maven and Java configuration including:
  • maven: Array of Maven dependencies (groupId, artifactId, version)
  • loadPaths: Array of paths to non-OSGi JAR files or directories
  • bundlePaths: Array of paths to OSGi bundle files or directories
  • reloadOnChange: Boolean to enable dynamic reload of updated classes
  • watchInterval: Interval in seconds to check for changes
  • watchExtensions: File extensions to monitor
  • "webservice": Structure with web service options (username, password, proxyServer, proxyPort, proxyUser, proxyPassword)
  • "component": Not used
  • "com": Not used  
  • delimiterOrVersion object  No Varies by object type:
  • "java":
    * Delimiter for classpath (default is comma)
    * Bundle version when using an OSGi bundle
  • "webservice": Not used
  • "component": Not used
  • "com": Not used