javaee / jersey

This is no longer the active Jersey repository. Please see the README.md
http://jersey.github.io
Other
2.86k stars 2.35k forks source link

helloworld-spring-annotations: ClassNotFoundException: javax.servlet.ServletContext #3739

Open akhalikov opened 6 years ago

akhalikov commented 6 years ago

Failed to run the example helloworld-spring-annotations in Idea or via command mvn exec:java with the exception:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
    at org.glassfish.jersey.server.spring.SpringComponentProvider.initialize(SpringComponentProvider.java:92)
    at org.glassfish.jersey.server.ComponentProviderConfigurator.lambda$null$0(ComponentProviderConfigurator.java:79)
    at java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:372)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1380)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at org.glassfish.jersey.server.ComponentProviderConfigurator.lambda$init$1(ComponentProviderConfigurator.java:80)
    at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:341)
    at org.glassfish.jersey.server.ResourceModelConfigurator.bindProvidersAndResources(ResourceModelConfigurator.java:135)
    at org.glassfish.jersey.server.ResourceModelConfigurator.init(ResourceModelConfigurator.java:87)
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:365)
    at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$1(ApplicationHandler.java:316)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
    at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:256)
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:315)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:282)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:269)
    at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:334)
    at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:138)
    at org.glassfish.jersey.examples.hello.spring.annotations.App.main(App.java:70)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 31 more
jansupol commented 6 years ago

Seems to be done by increasing commons-logging version from 1.1 to 1.2

akhalikov commented 6 years ago

The problem is that there is not servlet-api dependency in the classpath. Here is PR: https://github.com/jersey/jersey/pull/3741