<cfimport>
The tag import has multiple purposes:
- Import components with the attribute
path - Import Java classes (Lucee 6.2+) with the attribute
pathor its aliasjava - Import CFML/JSP custom tags with the attributes
prefixandtaglib
In script syntax, you can use:
cfimport(path="org.lucee.example.MyCFC");import org.lucee.example.MyCFC;import "org.lucee.example.MyCFC";
For importing multiple components, use the wildcard syntax:
import "org.lucee.example.*";
For Java classes (Lucee 6.2+), the classpath is shared between components and Java classes.
By default, Lucee first looks for cfml components and then for Java classes if not found.
Important: import only controls naming (letting you use short class names). It does not control which JAR or version 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.
Optionally, you can explicitly specify the type:
import java:java.util.HashMap;import cfml:org.lucee.cfml.Query;
Note: Imports only affect the current template, not the entire request.
Reference: Import
This tag cannot have a body.
This tag is also supported within <cfscript>
<cfimport
taglib=string
prefix=string
path=string
>
| Attribute | Description |
|---|---|
taglib
string, optional
|
edit
Path to a custom tag library or a JSP tag library descriptor (TLD). As cfimport is a compiler directive, Used in conjunction with the <cfimport prefix="my" taglib="/path/to/tags/">
In script: cfimport(prefix="my", taglib="/path/to/tags/");
|
prefix
string, optional
|
edit
Prefix by which to access the imported custom CFML or JSP tags. If you import a CFML custom tag directory and specify an empty value, "", for this attribute, you can call the custom tags without using a prefix. You must specify and use a prefix for a JSP tag library. Example usage after import: <my:customTag attribute="value">
|
path
string, optional
|
edit
Path of components or Java classes to be imported. For components:
For Java classes (Lucee 6.2+):
By default, Lucee uses a single classpath that includes both components and Java classes. When there's a naming conflict, Lucee first searches for a component, then for a Java class if the component is not found. Specifying the type prefix ( In script syntax, the keyword import org.lucee.example.MyCFC;
Note: The Alias: java |
Examples
editFormat for cfimport
<cfimport taglib="lib" prefix="t">
See also
- Java
- CreateObject()
- MavenLoad()
- Import
- Java Class Interaction
- JavaSettings in Application.cfc, Components and CFConfig.json
- Custom Tag Mappings
- Loading Java Libraries with Maven
- New Operator in Lucee
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)