users@jersey.java.net

java.lang.ClassNotFoundException: com.sun.jersey.json.impl.JSONUnmarshaller

From: Cheng Zhang <zhangyongjiang_at_yahoo.com>
Date: Fri, 7 Aug 2009 10:45:55 -0700 (PDT)

Hello,

I just started my first Jersey application and got an exception below.

              <![CDATA[java.lang.NoClassDefFoundError: com/sun/jersey/json/impl/JSONUnmarshaller
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at yjava.ws.util.jaxb.JAXBContextWrapper.createUnmarshaller(JAXBContextWrapper.java:154)
        at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getUnmarshaller(AbstractJAXBProvider.java:115)
        at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getUnmarshaller(AbstractJAXBProvider.java:98)
        at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:97)
        at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:519)
        at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:480)
        at com.sun.jersey.api.client.WebResource.handle(WebResource.java:561)
        at com.sun.jersey.api.client.WebResource.get(WebResource.java:179)
        at com.yahoo.sla.rest.PipelineAndGroupTest.testGroup(PipelineAndGroupTest.java:83)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:478)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:617)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:885)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:110)
        at org.testng.TestRunner.runWorkers(TestRunner.java:712)
        at org.testng.TestRunner.privateRun(TestRunner.java:582)
        at org.testng.TestRunner.run(TestRunner.java:477)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:324)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:319)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:292)
        at org.testng.SuiteRunner.run(SuiteRunner.java:198)
        at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:821)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:788)
        at org.testng.TestNG.run(TestNG.java:708)
        at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:62)
        at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:141)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
        at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
Caused by: java.lang.ClassNotFoundException: com.sun.jersey.json.impl.JSONUnmarshaller
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        ... 50 more
]]>
            </full-stacktrace>


Part of my maven pom file is as below,

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
            <version>1.1.1-ea</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>1.1.1-ea</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.1.1-ea</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.1.1-ea</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.test.framework</groupId>
            <artifactId>jersey-test-framework</artifactId>
            <version>1.1.1-ea</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.grizzly</groupId>
            <artifactId>grizzly-servlet-webserver</artifactId>
            <version>1.9.8</version>
            <scope>test</scope>
        </dependency>

Client side code throws the NoClassDefFoundError error:

        PipelineGroup response = webResource.path("group").path("1")
            .accept(MediaType.APPLICATION_XML)
            .get(PipelineGroup.class);

If I change the client side code to below, no exception and response is xml string representation of my object

        String response = webResource.path("group").path("1")
            .get(String.class);

Any idea?

Thanks a lot,
Kevin