Definition
A ColdFusion mapping is a named, virtual path that tells the CFML engine where to find files and components on disk. Think of it as a path alias: you assign a logical name like “/lib” to a physical folder (for example, C:\apps\shared\lib), and ColdFusion uses that alias to resolve includes, components, and Custom tags. Mappings do not change URLs in the browser; they work only inside ColdFusion to locate code and templates.
How It Works
Resolution basics
- A mapping is defined as a key-value pair:
- Key: a logical name starting with a leading slash, e.g., “/app”, “/com”, “/framework”.
- Value: the absolute directory path on the server.
- ColdFusion uses mappings to resolve:
- Component instantiation and inheritance:
new com.acme.Services.UserService()orextends="com.acme.framework.Base". - Template inclusion:
<cfinclude template="/app/views/header.cfm">. - Custom tags and modules:
<cfmodule template="/tags/widget.cfm">or<cfimport taglib="/tags/ui" prefix="ui">.
- Component instantiation and inheritance:
- For components (CFCs) referenced by dot notation (e.g.,
com.acme.Service), ColdFusion tries:- Relative to the current template or web root.
- Any defined application mappings whose names match the first segment (e.g., “/com”).
- Server-level mappings defined in the Administrator.
Note: The mapping name must include the leading slash for direct path-based resolution, and the first package token in dot notation must match a mapping name (minus the dot).
Where mappings are defined
- Server-wide (ColdFusion Administrator):
- Adobe ColdFusion: Server settings > Mappings.
- Lucee: Settings > Mappings (per web context/global).
- These mappings affect all applications running on that server context.
- Per-application (
Application.cfc):- Add entries to
this.mappingsto keep your app portable and self-contained. - Per-application mappings typically take precedence over server mappings with the same name.
- Add entries to
Creating a Mapping
In ColdFusion Administrator (Adobe CF)
- Go to Server settings > Mappings.
- Click Add New Mapping.
- Enter a logical path like “/core”.
- Enter an absolute directory path such as “D:/shared/core/”.
- Save and, if necessary, clear template/component cache after large moves.
In Lucee Administrator
- Web Administrator (per site) or Server Administrator (global) > Settings > Mappings.
- Follow a similar process; Lucee also supports per-application mappings via
Application.cfc.
In Application.cfc (recommended for portability)
Example using paths relative to the current file’s folder:
component {
this.name = “MyApp”;
base = getDirectoryFromPath( getCurrentTemplatePath() );
this.mappings[“/model”] = base & “model/”;
this.mappings[“/tags”] = base & “tags/”;
this.customTagPaths = [ base & “tags/” ];
}
Then you can:
- Create components: new model.services.UserService()
- Include templates:
- Load custom tags:
Tip: Use getDirectoryFromPath(getCurrentTemplatePath()) (or expandPath("./") carefully) to avoid hard-coded drive letters.
Practical Example: Sharing a Framework Across Multiple Sites
Imagine several CFML sites share the ColdBox framework, stored once at D:/cf-libs/coldbox/.
- Define a mapping:
- In Administrator or Application.cfc:
- this.mappings[“/coldbox”] = “D:/cf-libs/coldbox/”;
- In Administrator or Application.cfc:
- Reference ColdBox in your app:
- Instantiate:
application.cbController = new coldbox.system.web.Controller(); - In
Application.cfc, the framework can be bootstrapped using its mapped path.
- Instantiate:
- Include framework assets (if any templates need inclusion):
<cfinclude template="/coldbox/templates/someHelper.cfm">
Result: Each site uses the same, central framework installation. Updates happen in one place without copying files across projects.
Use Cases
- Centralized libraries and frameworks:
- Map “/framework” or “/coldbox” to a shared install.
- Keep code outside the web root:
- Map “/app” to a secure directory not directly accessible via HTTP, enhancing Security for Business logic.
- Multi-tenant or multi-site deployments:
- Share common components, services, and views across sites with minimal duplication.
- Clean up legacy paths:
- Retain old include/component references by creating mappings that point to new locations during refactors.
- Unit testing and tooling:
- Point test harnesses at versioned directories with simple mapping flips between branches.
Pros and cons
| Aspect | Pros | Considerations |
|---|---|---|
| Portability | Per-app mappings make code relocatable. | Hard-coded admin mappings can create environment drift. |
| Security | Keep sensitive CFCs outside web root. | Mappings don’t block includes; enforce sandbox/file permissions. |
| Maintainability | Centralize common libraries; easier upgrades. | Poor naming collisions (e.g., two “/com” mappings) cause confusion. |
| Performance | CF caches resolved templates/components. | Changes in mapped folders may need cache clears or restarts. |
| Clarity | Explicit logical paths improve readability. | Mixed usage (relative + mapping + server alias) can be opaque. |
Best practices
- Prefer per-application mappings
- Define
this.mappingsinApplication.cfcfor portability across dev, test, and prod.
- Define
- Use clear, unique names
- Short, descriptive names like “/core”, “/model”, “/coldbox”. Avoid generic names that could clash with other apps.
- Avoid hard-coded absolute paths in code
- Derive paths from the executing template location using
getDirectoryFromPath(getCurrentTemplatePath()).
- Derive paths from the executing template location using
- Keep Business logic outside the web root
- Map secure directories and reference them via mappings to prevent accidental exposure via HTTP.
- Document your mappings
- Maintain a short README listing all mappings and their purposes to onboard teammates quickly.
- Mind platform differences
- Use forward slashes in paths for Cross-platform friendliness; verify case sensitivity on Linux/UNIX.
- Coordinate with sandbox/security policies
- If using Adobe CF Sandbox security or Lucee security, grant read/execute permissions to mapped folders as needed.
- Test resolution conflicts
- If a real folder and mapping share a name, prefer explicit references and verify which is being resolved.
- Cache and Deployment hygiene
- After moving mapped directories, clear template/component caches or restart to avoid stale resolutions.
Comparison: ColdFusion mapping vs. Web Server Alias
| Feature | ColdFusion Mapping | Web Server Alias/Virtual Directory | OS Symlink/Junction |
|---|---|---|---|
| Purpose | Resolve CFML includes, CFCs, tags. | Map HTTP URLs to disk paths. | Filesystem-level path redirection. |
| Visible in Browser | No | Yes | Indirectly (as part of a real path). |
| Defined In | CF Admin or Application.cfc | IIS/Apache/Nginx | OS/filesystem tools |
| Affects CF Component Resolution | Yes | No | Possibly, because it changes the actual filesystem. |
| Portability | High with per-app mappings | Varies; tied to web Server config | Varies; requires OS support. |
Key takeaway: A ColdFusion mapping is internal to the CFML engine and does not automatically create a public URL. A web server alias is for HTTP routing. They solve different problems.
Key Points
- A ColdFusion mapping is a logical path alias to a physical directory.
- Use it to load CFCs, includes, and custom tags without depending on the web root.
- Define mappings per application for portability; use the Administrator for server-wide needs.
- Mappings enhance security by letting you store code outside the web root.
- For components in dot notation, the first package token must match a mapping name (e.g., “/com”).
Troubleshooting Tips
- “Could not find the ColdFusion Component” errors:
- Verify the mapping name matches the first dot-token, and the directory structure mirrors the package path.
- “Could not find the include template”:
- Confirm that
<cfinclude template="/mapping/...">uses a correct mapping name and that the physical path exists.
- Confirm that
- Inspect mappings at runtime:
- Dump
getApplicationSettings()(Adobe CF) orgetApplicationSettings()equivalent in Lucee to seemappingsandcustomTagPaths.
- Dump
- Clear caches:
- After moving mapped folders, clear template/component caches or restart the app/server.
- Log and diagnose:
- Add temporary diagnostics in
onApplicationStart()to checkthis.mappingsand resolved paths withfileExists()/directoryExists().
- Add temporary diagnostics in
FAQ
Do mappings change how users access URLs in the browser?
No. A mapping is an internal ColdFusion alias for resolving files. It does not create or modify public URLs. If you need a public URL, configure a web server alias/virtual directory.
Should the mapping name include a leading slash?
Yes. Mapping names are conventionally defined with a leading slash (e.g., “/model”, “/com”). For component dot-notation, the first token should correspond to the mapping name without the slash.
What’s the difference between server-level and per-application mappings?
Server-level mappings (Administrator) apply to all apps within that server context. Per-application mappings (this.mappings in Application.cfc) apply only to that app and are better for portability and Version control.
Yes. You can set this.customTagPaths and use <cfmodule> or <cfimport> with mapping-based paths, making tag libraries portable and centralized.
Do mappings improve security?
They help by allowing you to keep sensitive code outside the web root. However, mappings alone don’t enforce security—use sandboxing/permissions and safe coding practices (e.g., never include templates based on unvalidated user input).
