Setting 'lucee-server-directory' init param not working in embedded Tomcat

Hi all,

I’m been playing around with running Lucee within embedded Tomcat with the intention to make a standalone and portable application, but I’m unable to get the lucee-server to point to the right directory.

Here’s a snippet of my Tomcat initialisation…

final String serverRootPath = new File(configProperties.getPropertyValue(Arguments.SERVER_ROOT_PATH)).getAbsolutePath();
ctx.getServletContext().getServletRegistrations().get(cfmlServletName).setInitParameter("lucee-web-directory", serverRootPath + "/WEB-INF");
ctx.getServletContext().getServletRegistrations().get(cfmlServletName).setInitParameter("lucee-server-directory", serverRootPath + "/lucee-server");

With the above, a ‘lucee-server’ directory is created so there’s clearly something in the CFML engine doing its thing, but then it doesn’t actually appear to use the directory for anything, and remains empty once started up.

Weirdly, redirecting the ‘lucee-web-directory’ works just fine and results in my WEB-INF folder appearing there.

I was able to locate the lucee-server directory by checking the pageContext, and it appears to be running from my Gradle caching directory, which makes sense as I have the Lucee jar as a dependency in my build.gradle, retrieved from maven central.

To code is available here if you need more context.

Everything otherwise works correctly!

edit: I also tried this…
System.setProperty("lucee.server.dir", serverRootPath + "/lucee-server");
…which had the exact same result as the above. ‘lucee-server’ folder was created but wasn’t used.

Anyone have any idea how I can get it redirecting correctly? I went back to a Lucee version from several years ago and the same thing happened, so I wonder if embedded Tomcat isn’t completely supported, or if I’m just doing something dumb.

Don’t forget to tell us about your stack!

OS: Windows 10 64bit
Java Version: Java 14.01
Tomcat Version: 9.0.41
Lucee Version:

Thanks all.

For posterity, I did manage to solve this!

It turned out a call to Log4j2 (before I even initialised embedded Tomcat) was invoking ScriptEngineManager, which in turn (using reflection) would initialise all script engines on the classpath (I think!). Lucee happens to be one, so the lucee-server would be unpacked before my Tomcat setInitParameter(“lucee-server-directory”) could be used.

Weirdly, this also creates an unusuable Lucee web-context, presumably for the script engine.

If anyone else uses Log4j2, Tomcat and Lucee, feel free to chime in so I can pick your brain :slight_smile:


1 Like