Skip to main content
Ben Nadel at CFinNC 2009 (Raleigh, North Carolina) with: Zeljka Majetic
Ben Nadel at CFinNC 2009 (Raleigh, North Carolina) with: Zeljka Majetic@zeljkaNYC )

Confusion Over this.mappings And expandPath() Not Working In Lucee CFML

By on

So, I've spent the last 3-hours this morning trying to understanding why my this.mappings configuration in my Application.cfc ColdFusion component "wasn't working" in Lucee CFML After much trial-and-error and many Google searches, it seems that the evaluation of the this.mappings paths gets "confused" (depending on how you look at it) if you attempt to reference a directory that does not yet exist. To be honest, I had no idea that the physical file-system had any impact whatsoever on the evaluation of CFML mappings; so, it didn't occur to me that a folder had to exist before I tried to reference it in a mapping. That said, I wanted to record my journey here in case anyone else stumbles over the same issue in Lucee CFML

To demonstrate this confusion, let's create an Application.cfc with a single mapping that points to a folder in the file-system that we have not yet created:

component { = "mappings-demo";

	this.webrootDir = getDirectoryFromPath( getCurrentTemplatePath() );
	this.mappings = {
		"/a": "#this.webrootDir#vendor/lib-a/"


Notice that we are mapping /a to ./vendor/lib-a. Now, let's create an index file that attempts to consume that mapping:


	dump( expandPath( "/a/config.ini" ) );


All we're trying to do here is output the evaluation of the mapped path. And, if we run this Lucee CFML code before we create the vendor directory, we get the following page output:


Notice that the reference to /a was not mapped to /vendor/lib-a. Instead, Lucee just used / as a reference to the root of the ColdFusion server.

Ok, now let's try to add another mapping to an existing folder. First, let's update our Application.cfc ColdFusion framework component:

component { = "mappings-demo";

	this.webrootDir = getDirectoryFromPath( getCurrentTemplatePath() );
	this.mappings = {
		"/a": "#this.webrootDir#vendor/lib-a/",
		"/b": "#this.webrootDir#vendor/lib-b/"


This time, we're mapping /b onto ./vendor/lib-b.

Now, before we attempt to consume this mapping, let's ensure that lib-b actually exists in the physical file-system:

Bens-MBP:testing-lucee bennadel$ pwd
Bens-MBP:testing-lucee bennadel$ mkdir -p mappings-demo/vendor/lib-b

And, now that lib-b actually exists, let's update our index.cfm file to try and consume the new /b path mapping:


	dump( expandPath( "/b/config.ini" ) );


If we run this Lucee CFML code, we get the following output:


As you can see, this time, the mapping worked. The prefix /b was successfully mapped to ./vendor/lib-b in the expandPath() evaluation. The only difference in this execution was the fact that the this.mappings folder existed before it was referenced within the Application logic.

It's definitely possible that you will never run into this issue since you are likely to be configuring this.mappings to point to existing folders. However, I was just doing some Research and Development (R&D) and wanted to make sure that my ColdFusion mappings were working before I attempted to consume them. This is when I stumbled upon the fact that the physical folder has to exist first. At least, in Lucee CFML

Epilogue On Cached Paths

If you run into this issue, you may find that a failed this.mappings path evaluation continues to fail even after you create the physical folder. It looks like the path evaluations get cached somewhere in the ColdFusion Application state. At that point, you need to restart the ColdFusion application in order to pickup the correct path evaluation.

Want to use code from this post? Check out the license.

Reader Comments



Here is a ticket that touches on this topic:

And, ironically, I just found a message on this blog from 2013 pointing out mappings fail if the folder doesn't exist (from Sumit Verma):

One thing to be careful about expand path is, it doesn't work if the file or directory doesn't exist. It doesn't throw error, but it returns wrong path.




One thing that I just learned is that - in Lucee CFML - relative paths work in application mappings:

All the getDirectoryFromPath( getCurrentTemplatePath() ) hoops that I normally jump through after years of using Adobe ColdFusion are gone. Now, I can simply use ../ values relative to the location of the Application.cfc file. Amazing!

Post A Comment — I'd Love To Hear From You!

NEW: Some basic markdown formatting is now supported: bold, italic, blockquotes, lists, fenced code-blocks. Read more about markdown syntax »
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.