Search code examples
jspservletsannotationsjava-ee-6servlet-filters

Can you package a WebFilter into a library


And if so how do you do it?.

Yes sounds like my last question. And it is essentially the same problem. I have a @javax.servlet.annotation.WebFilter which works fine when packaged directly into a war. Now I would like to move the filter in to a library. But if I do so it won't be called any more.

Any pitfalls I have to look out for or is it just plain impossible?


Solution

  • Set <web-app metadata-complete="false">.

    This means that the metadata for this web application is not limited to this particular xml (and the classes of the webapp), but can use metadata by 3rd party libraries.

    Also take a look at "web fragments". You can define a web-fragment.xml in META-INF of your jar, and map all servlets and filters there.

    Take a look at this demo.