ClassNotFoundException: org.datanucleus.api.rest.RestServlet while using datanucleus rest api


bharani.s@...
 

Hi,

Trying to use the datanucleus rest api. 

I have the POJO classes created for entity and trying to access them as resources. Following the instructions given in this link..
http://www.datanucleus.org/products/accessplatform_4_1/rest/api.html

but it fails with the following message

Exception

javax.servlet.ServletException: Error instantiating servlet class org.datanucleus.api.rest.RestServlet
.......

Root Cause

java.lang.ClassNotFoundException: org.datanucleus.api.rest.RestServlet


dependencies used in pom.xml given below 

           <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
    <dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-core</artifactId>
    <version>[5.0.0-m1, 5.9)</version>
</dependency>
 
<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-api-rest</artifactId>
    <version>5.1.0-release</version>
</dependency>

<dependency>
    <groupId>javax.jdo</groupId>
    <artifactId>jdo-api</artifactId>
    <version>3.1</version>
</dependency>
 
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jdo</artifactId>
            <version>[5.0.0-m1, 5.9)</version>
        </dependency>
 
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jpa</artifactId>
            <version>[5.0.0-m1, 5.9)</version>
        </dependency>
 
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>javax.persistence</artifactId>
            <version>2.2.0-release</version>
        </dependency>
 
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-rdbms</artifactId>
            <version>[5.0.0-m1, 5.9)</version>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <!--version>1.8.0.4</version-->
            <version>2.3.4</version>
        </dependency>    
 
web.xml has the following servlet mapping 

      <servlet>
        <servlet-name>DataNucleus</servlet-name>
        <servlet-class>org.datanucleus.api.rest.RestServlet</servlet-class>
        <init-param>
            <param-name>persistence-context</param-name>
            <param-value>myPMFName</param-value>
        </init-param>      
    </servlet>
 
    <servlet-mapping>
        <servlet-name>DataNucleus</servlet-name>
        <url-pattern>/dn/*</url-pattern>
    </servlet-mapping>
I see a similar message posted in stackoverflow, having version mismatch in dependencies as a possible reason.

Can someone help?

Regards
Bharani


Andy
 
Edited

ClassNotFoundException is one of the simplest Java exceptions. The class is not in the CLASSPATH at runtime.
datanucleus-api-rest does indeed have that class.

"version mismatch in dependencies" is not a possible reason for that error when the class has not changed package.

FWIW Not sure why you refer to docs for DN 4.1 when allegedly using 5.1.


bharani.s@...
 

Thanks Andy for the response.

Yes - I am aware, why this (ClassNotFoundException) error is normally thrown. The Jar files and dependencies are part of the package, as I have given in the pom.xml 'dependency' section.
This is the stackoverflow link I was referring to earlier, where it is suggested by 'DataNucleus' (not sure if its the official handle), that this could happen due to version mismatch in dependencies.

https://stackoverflow.com/questions/11066312/errors-in-using-datanucleus-rest-api

I have looked at the 5.1 link as well - it is same as the 4.1 contents

Thanks
Bharani


Andy
 
Edited

It's only going to be the classpath, and what classpath is available for the class loader.
So debug your classpath by printing out what is there (a pom says nothing because it doesn't show how you start up whatever you are doing) and what class loading you have. That is the only way you find your problem