Reputation: 2543
I'm facing some problems running a simple RESTful web service with Jersey with a TomEE server. (This is the tutorial i'm following: http://www.vogella.com/tutorials/REST/article.html though I'm using Maven for my dependencies and TomEE JAX-RS as my server). When I run the server, I get the following error:
org.apache.openejb.OpenEJBException: Unable to load servlet class: org.glassfish.jersey.servlet.ServletContainer: org.glassfish.jersey.servlet.ServletContainer
at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:2113)
at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:1843)
at org.apache.openejb.config.AnnotationDeployer.deploy(AnnotationDeployer.java:360)
at org.apache.openejb.config.ConfigurationFactory$Chain.deploy(ConfigurationFactory.java:401)
at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:962)
at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1214)
at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1087)
at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
The servlet class is derived from my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>RestTest</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<!-- Register resources and providers under com.vogella.jersey.first package. -->
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.vogella.jersey.first</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
And these are my dependencies in the project's maven pom.xml file:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.14</version>
<scope>provided</scope>
</dependency>
This is my first time using a TomEE JAX-RS server, (and on top of that, I've been using microsoft server technology for the past few years), so please comment if I havn't supplied enough information for you to work on a solution.
Upvotes: 2
Views: 3439
Reputation: 12865
You shouldn't use provided
scope for your Jersey dependencies.
provided
indicates that the dependency is provided by the runtime environment (i.e. TomEE) and should not be included in your web app. But that's not the case with TomEE.
TomEE web profile does not include JAX-RS at all. TomEE Plus includes CXF for JAX-RS, but not Jersey.
Anyway, Jersey 2.x implements JAX-RS 2.0 for Java EE 7, but TomEE is Java EE 6, so you shouldn't expect your use case to work out of the box.
Upvotes: 6