users@jersey.java.net

[Jersey] Fwd: Re: issue with embedded jetty 9.0.1 and jersey 2.5.1

From: Quintes van Aswegen <mycatchallaccount_at_gmail.com>
Date: Mon, 23 Jun 2014 17:00:10 +0200

Hi Michal,

That works perfectly, many thanks


Quintes

---------- Forwarded message ----------
From: Michal Gajdos <michal.gajdos_at_oracle.com>
Date: Mon, Jun 23, 2014 at 3:43 PM
Subject: [Jersey] Re: issue with embedded jetty 9.0.1 and jersey 2.5.1
To: users_at_jersey.java.net


Hi Quintes,

remove jetty-maven-plugin from your dependencies (it’s a build plugin and
it’s causing you the issues). Plus make sure you’re not using Jersey 1.x
properties (prefix com.sun.jersey):

        Server server = new Server(8081);
        ServletContextHandler context = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS);
        context.setContextPath("/");
        server.setHandler(context);


        ServletHolder servletHolder =
context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/api/*");

servletHolder.setInitParameter("jersey.config.server.provider.packages",
"quintes.rest");

        try {
            server.start();
            server.join();
        } catch (Throwable t) {
            t.printStackTrace(System.err);
        }

your resource would be available at http://localhost:8081/api/test

Michal

On 23 Jun, 2014, at 13:32 , Quintes van Aswegen <mycatchallaccount_at_gmail.com>
wrote:

Good Day,

I have posted this to so
http://stackoverflow.com/questions/24360922/jersey-error-java-lang-incompatibleclasschangeerror-implementing-class-in-jetty

running jersey 2.5.1 and embedding jetty jetty-9.1.2.v20140210

I want an embedded jetty server capable of servlet 3x as well as jersey. I
know that my jetty instance works as servlet handler and static file
hander. however the following details I get this error:
java.lang.IncompatibleClassChangeError: Implementing class

I am sure it is related to cglib / asm but not sure how to fix it.

Here's the project :
https://onedrive.live.com/redir?resid=E77A3FF7CCD2841F!117&authkey=!ABSHwGIMoA4314o&ithint=file%2c.zip

The pom looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>my.test</groupId>
<artifactId>embedjettyX</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>embedjettyX</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests>
<jersey.version>2.5.1</jersey.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>

</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-util</artifactId>
<version>3.1</version>
</dependency>-->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.1.2.v20140210</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.1.2.v20140210</version>
</dependency>
<!-- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>

</dependency>-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>

</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<type>jar</type>
</dependency>
<!-- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
</dependency>-->

<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-deploy</artifactId>
<version>9.1.2.v20140210</version>
</dependency>

</dependencies>
</project>

the rest app class like this:
@ApplicationPath("/")
public class Application extends ResourceConfig {

public Application() {
packages("quintes.rest");
}


}

the REST resource:
@Path("test")
public class restresource {

@GET
@Produces({MediaType.APPLICATION_JSON})
public Response getDefault() {
return Response.ok("test returned").build();
}

}

and the main() like this:
public class App {

public static void main(String[] args) {

Server server = new Server(8081);
ServletContextHandler context = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
server.setHandler(context);


ServletHolder servletHolder =
context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/api/*");
servletHolder.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
"com.sun.jersey.api.core.PackagesResourceConfig");

servletHolder.setInitParameter("com.sun.jersey.config.property.packages",
"quintes.rest");

ServletHolder staticServlet = context.addServlet(DefaultServlet.class,
"/*");
staticServlet.setInitParameter("resourceBase", "src/main/webapp");
staticServlet.setInitParameter("pathInfoOnly", "true");

try {
server.start();
server.join();
} catch (Throwable t) {
t.printStackTrace(System.err);
}
}
}

however I get the error mentioned as part of this stack trace:
2014-06-23 09:26:49.502:WARN:oejs.ServletHandler:qtp28971452-13: Error for
/api/
java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at
org.glassfish.jersey.server.ResourceConfig.scanClasses(ResourceConfig.java:875)
at
org.glassfish.jersey.server.ResourceConfig._getClasses(ResourceConfig.java:840)
at
org.glassfish.jersey.server.ResourceConfig.getClasses(ResourceConfig.java:755)
at
org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1171)
at
org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1144)
at
org.glassfish.jersey.server.ResourceConfig.createRuntimeConfig(ResourceConfig.java:1140)
at
org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:299)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
at
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:169)
at
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:359)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at
org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:561)
at
org.eclipse.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:424)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:690)
at
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:552)
at
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1112)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:479)
at
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1046)
at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:459)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:281)
at
org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:232)
at
org.eclipse.jetty.io.AbstractConnection$1.run(AbstractConnection.java:505)
at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
at java.lang.Thread.run(Thread.java:744)

What am i doing wrong?

thanks
q