简体   繁体   中英

NoClassDefFoundError when loading servlet filter from jar

I created a servlet filter which I'm trying to use in WildFly 26 with an application deployed as an EAR file, so I added this to the web.xml file:

<filter>
    <filter-name>LoggingFilter</filter-name>
    <filter-class>org.stormhub.jakarta.LoggingFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>LoggingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

The servlet filter resides in the org.stormhub.jakarta package and implements the jakarta.servlet.Filter interface.

This is what the deployed EAR file looks like:

some.ear
|
|-- some.war
    |
    |-- WEB-INF/
        |
        |-- lib/
            |
            |-- servlet-logging-filter-1.0.0.jar

The servlet-logging-filter-1.0.0.jar file looks like this:

org
|
|-- stormhub
    |
    |-- jakarta
        |
        |-- LoggingFilter.class

When starting WildFly it prints the error message:

Failed to define class org.stormhub.jakarta.LoggingFilter 
in Module "deployment.some.ear.some.war" 
from Service Module Loader: java.lang.NoClassDefFoundError: 
Failed to link org/stormhub/jakarta/LoggingFilter 
(Module "deployment.some.ear.some.war" from Service Module Loader): 
jakarta/servlet/Filter

Why is the class loader not finding my servlet filter?

WildFy 26 is a Jakarta EE 8 . WildFly 26 Preview is a Jakarta EE 9.1 container and WildFly 27 is a Jakarta EE 10 container. If you want to use Jakarta EE 9+, jakarta namespaced API's, you need to use WildFly 26 Preview or better yet WildFly 27.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM