Reputation: 1111
I have a new nexus server, and a new build server. I mvn package a project and get the following error when it gets to the testing phase:
org.mule.api.registry.RegistrationException: Failed to invoke lifecycle phase "initialise" on object: org.mule.config.bootstrap.SimpleRegistryBootstrap@191a01dd (org.mule.api.lifecycle.LifecycleException)
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 80 more
NOT FOUND
I created a barebone archetype pom as I was troubleshooting this. This included javax.servlet, so I figured that might be it, and it did seem to solve the problem.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api-release-version}</version>
<scope>provided</scope>
</dependency>
Open ended question - why might this be?
Upvotes: 0
Views: 1291
Reputation: 18194
When you are compiling classes which are importing something from javax.servlet
package, you need to have that dependency on your class path.
For example when you have public class FooServlet extends HttpServlet
, then the Java compiler needs to be able to get javax.servlet.http.HttpServlet
to check whether the parent is not final
, whether you are implementing all abstract methods, etc.
javax.servlet
dependency then needs to be marked as provided
in pom.xml
. This is because all servlet containers already include that dependency. If you fail to exclude this library from you WAR, the HttpServlet
class in your web application will be different from HttpServlet
class used by the servlet container (i.e. FooServlet instanceof HttpServlet
would be false as classes in Java are not only defined by their qualified name, but also by their class loader).
Upvotes: 1