Cfimport JSP Tags are not working

I am using cfimport taglib to use JSP tags, but it is not working because of the Tag Class NoClassDefFoundError.

<cfimport taglib="/WEB-INF/tld/security.tld" prefix="sso">
<sso:test />

I’ve running this sample in Wildfly-26.1.13.Final with Lucee-5.3.10.97 and it errors out by saying Caused by: java.lang.NoClassDefFoundError: com/accela/security/taglib/TestTag.

For a more detailed log which could bring some ideas -

Caused by: java.nio.file.NoSuchFileException: 
C:\A-Tools\wildfly-26.1.3.Final\standalone\tmp\vfs\temp\temp7c56db823b6314f8\content-d7a368ceb12bbe9f\WEB-INF\lucee\cfclasses\CFC__A_Tools_wildfly_26_1_3_Final_standalone_tmp_vfs_temp_temp7c56db823b6314f8_content_d7a368ceb12bbe9f37773\com\accela\security\taglib\TestTag.class

My question is - why Lucee is looking for the Tag Class in lucee\cfclasses folder instead of the lib folder. Is there a way to specify the Tag Classes’ Location? because typically our classes are in lib\jars.

Download the express version of lucee and try that as a comparison.

Just tried lucee-express and it behaves the same -
image

Spark, you don’t say exactly which lib folder you’ve put the jar in. Since one can install or implement lucee many ways, the location(s) which would work can vary.

Further, you say you put it in a jars folder under that. What if you put it in the lib, rather than lib/jars? Restart lucee if you try that.

If that still doesn’t work, in your lucee deployment, find the WEB-INF/lib folder and place the jar there and try that (with a lucee restart).

Finally, as another check (even if was not needed with CF), try changing the cfimport taglib=“/WEB-INF/tld/security.tld” to name the taglib as /WEB-INF/lib/your.jar, naming your jar (and restart lucee). And put the tld in the same folder as the jar. Then restart and test.

I’m not saying these things because I have confirmed jsp custom tags work in Lucee (though I had used and written about using them with CF about 20 years ago…but they never seemed to take off). I’m also not saying you MUST do things this way for them to work in Lucee, let alone that you will “have to change all your references to work this way”.

I’m just trying to help you think through some options to consider…and I’m writing this on a phone, so not testing them first. If we find what works, THEN we can maybe figure why that was needed and whether something could be done to avoid you having to change a lot of code (if you would have to).

Or maybe someone with more specific lucee experience with jsp custom tags will offer something.

1 Like

Thanks for your reply and sorry I didn’t make myself more clear on the class/lib path.
The lib path I am referring is the WEB-INF/lib.
The current test I am doing is - deploy the lucee-5.3.10.97.war to a Wildfly Server. Also tried with Lucee-Express.
And I am able to use createObject to create that JSP Tag Class, which means in some way the tag class is available in Lucee classpath.
Meanwhile, this works fine with both CodeFusion-7.2.0 and Railo-3.1.8, since I am migrating the project from CF&Railo to Lucee.

1 Like

Anyone has any other ideas on this? This is not working for me and it appears to me that the <cfimport taglib JSP tags is not working properly with Lucee classpath.
I figured <cfimport is at compile time, which I don’t know how Lucee could work with Java JSP Tag Classes since they are already in the jar and not compiled the same as cfm during Lucee start up.

While you await any ideas from others, had you tried my second one: “try changing the cfimport taglib=“/WEB-INF/tld/security.tld” to name the taglib as /WEB-INF/lib/your.jar, naming your jar (and restart lucee). And put the tld in the same folder as the jar. Then restart and test.”

Hey carehart, I’ve tried every possible way of using taglib with cfimport. Like I said, it is not working with <cfimport taglib, but it is working with createObject.
To be clear, I have tried all your ideas in your last comment and no luck.
And the Lucee is looking for the Tag Class in lucee\cfclasses folder. Also when I manually place the tag class in that lucee\cfclasses folder, it is able to find the class, but it throws Class Cast Exception with the same class name.

I had an java.lang.NoClassDefFoundError once and it was due to a missing dependency in the specific jar that I was trying to load. Are you sure you have uploaded all needed dependencies?

Hey Andreas,

I’ve tried using this example Example of JSP Custom Tag - javatpoint and it works the same. Works for createObject, but not <cfimport taglib

Hi carehart, this issue is blocking me for a while. Could you try using this tag.jar and test on your end? The tag code basically comes from here - Example of JSP Custom Tag - javatpoint
tag.jar (1.8 KB)

By using below code, I am having the issue posted -

<cfimport taglib="/WEB-INF/lib/tag.jar" prefix="m">
<m:today />

Anyone could make this work, please let me know what I’ve been doing wrong and I would be very appreciated.
Thanks.

It looks like you are lacking the needed java libs to run your tag file. You would need to enable jsp support to have that tag.jar work.

Thanks for your reply. I tested both Lucee Express and Wildfly with Lucee WAR and I am pretty sure that JSP is working fine in the environment. And also, JSP Tags inside JSP files are working fine as well. It only breaks when using it in CFMX. There could be a dependency that I am lacking, but it’s kind hard for me to find it.

Lucee Express stacktrace -

Caused by: java.lang.NoClassDefFoundError: com/javatpoint/sonoo/MyTagHandler
  ... 36 more
 Caused by: java.lang.ClassNotFoundException: Class [com.javatpoint.sonoo.MyTagHandler] is invalid or doesn't exist
  at lucee.commons.lang.PhysicalClassLoader.findClass(PhysicalClassLoader.java:163)
  at lucee.commons.lang.PhysicalClassLoader.loadClass(PhysicalClassLoader.java:144)
  at lucee.commons.lang.PhysicalClassLoader.loadClass(PhysicalClassLoader.java:127)
  at lucee.commons.lang.PhysicalClassLoader.loadClass(PhysicalClassLoader.java:121)
  ... 36 more
 Caused by: java.nio.file.NoSuchFileException: C:\Users\sou\Downloads\lucee-express-5.3.10.97\webapps\ROOT\WEB-INF\lucee\cfclasses\CFC__Users_sou_Downloads_lucee_express_5_3_10_97_webapps_ROOT22590\com\javatpoint\sonoo\MyTagHandler.class
  at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
  at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
  at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
  at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
  at java.nio.file.Files.newByteChannel(Files.java:361)
  at java.nio.file.Files.newByteChannel(Files.java:407)
  at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
  at java.nio.file.Files.newInputStream(Files.java:152)
  at lucee.commons.io.res.type.file.FileResource.getInputStream(FileResource.java:243)
  at lucee.commons.io.IOUtil.copy(IOUtil.java:190)
  at lucee.commons.lang.PhysicalClassLoader.findClass(PhysicalClassLoader.java:159)

For a testing comparison, running with Wildfly deployed with Lucee WAR -

  • Using cfscript createObject to check if the Tag Class is available in the Classpath — It works
  • Using a test.jsp file which calls the JSP Tag inside the JSP file, and access the test.jsp directly — it works
  • Testing the test.jsp from a CFM file, by using GetPageContext().include("test.jsp");It works
  • Using <cfimport taglib and test the JSP Tag — not working

test.jsp file -

<%@ taglib uri="WEB-INF/tld/mytags.tld" prefix="mm" %>
Current Date and Time is: <mm:today/>

test.cfm -

<cfoutput>Test Page</cfoutput></br>
<cfoutput>Using `cfscript createObject`: </cfoutput>
<cfscript>
 obj1 = createObject("java", "com.javatpoint.sonoo.MyTagHandler");
</cfscript>
<cfoutput>=====> #obj1#</cfoutput> </br></br>
<cfoutput>Using `GetPageContext.include(JSP)` file with JSP Tag: =====> </cfoutput>
<cfscript>
 GetPageContext().include("test.jsp");
</cfscript>

</br></br>
<cfoutput>Using `cfimport taglib` to use Tag: </cfoutput></br>
<cfimport taglib="WEB-INF/tld/mytags.tld" prefix="m">
<m:today/>

Test Page ===>