Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix scanning of ServletContainerInitializer by tomcat > 7.0.5x #20

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

bmeriaux
Copy link

ServletContainerInitializer not scanned in goal "run"

I found that since tomcat v7.0.5x , because of a refactor on the scanning of the ServletContainerInitializer, it is broken in the tomcat maven plugin in the run goal.

The bug is introduced by the new method of scanning of the new class "org.apache.catalina.startup.WebappServiceLoader" in tomcat core.

The method "load" looks for lib jar path using servletContext.getResource() with the prefix "WEB-INb/lib", but in "run" goal, we do not have the dependencies in this folder, and because the method do not use the classloader, all lib jars are not scanned.

The problematic code path is used if the "servletContext.getAttribute(ServletContext.ORDERED_LIBS);" return a list.

But if we clear this list, the load method will scan every jar in the classpath.

To fix the problem we have three solutions:
clear the servletContext attribute ServletContext.ORDERED_LIBS,
or get the lib loaded in dependencies accessible by servletContext.getResource("WEB-INb/lib" + jarName),
or put the dependencies in the parent classloader

The first solution can be easily implemented by extending the ContextConfig class to override the processServletContainerInitializers method in the following way.

protected void processServletContainerInitializers(ServletContext servletContext) {
List saveOrderedLib = (List) servletContext.getAttribute(ServletContext.ORDERED_LIBS);
servletContext.setAttribute(ServletContext.ORDERED_LIBS, null);
super.processServletContainerInitializers(servletContext);
servletContext.setAttribute(ServletContext.ORDERED_LIBS, saveOrderedLib);
}

and using this custom ContextConfig class in the ExtendedTomcat class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant