Import
Import
Import components, Java classes (6.2+), or custom tags.
Components
Tag Syntax
<cfimport path="org.lucee.example.MyCFC">
<cfscript>
// Create an instance of the imported component
myInstance = new MyCFC();
</cfscript>
Script Syntax
Using the import keyword:
<cfscript>
import org.lucee.example.MyCFC;
// Create an instance of the imported component
myInstance = new MyCFC();
</cfscript>
Quotes also work:
<cfscript>
import "org.lucee.example.MyCFC";
</cfscript>
Or the cfimport function:
<cfscript>
cfimport( path="org.lucee.example.MyCFC" );
myInstance = new MyCFC();
</cfscript>
Wildcard Import
<cfscript>
import "org.lucee.example.*";
// Create an instance of a component from the imported package
myInstance = new MyCFC();
</cfscript>
Java Classes (6.2+)
Import saves you typing fully qualified class names - that's all it does. It doesn't control which version of a library is loaded.
If you need a specific library version (especially when it conflicts with Lucee's bundled libraries), use javasettings to specify the dependency. See Java Class Interaction for details.
import java.util.HashMap;
To resolve naming conflicts with CFML components:
import java:java.util.HashMap;
import cfml:org.lucee.cfml.Query;
Imports only affect the current template.
Custom Tags
<cfimport prefix="my" taglib="/path/to/tags/">
<!-- Use a custom tag from the imported tag library -->
<my:customTag attribute="value">
Script: cfimport(prefix="my", taglib="/path/to/tags/") (the import keyword doesn't work for custom tags).