Love Hasija
Love Hasija

Reputation: 2568

Implementing Rest Easy with Tomcat

I have a Dynamic Web Project with a set of jsp's and a custom controller servlet, that is working great. But, I also need to implement a rest easy exposed service on it, and that's why i changed the web. xml to contain rest easy servlet also. and the application class which invokes the rest easy resource. But, when i am adding changes to web.xml, it is hitting rest easy servlet, but throwing exception..

java.lang.ClassNotFoundException: org.scannotation.AnnotationDB$CrossReferenceException

Web.xml :

   <servlet>
<display-name>ControllerServlet</display-name>
<servlet-name>ControllerServlet</servlet-name>
<servlet-class>com.example.ControllerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>CollRestApi</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    <init-param>
      <param-name>javax.ws.rs.Application</param-name>
      <param-value>com.exampl.RestApiApplication</param-value>
    </init-param>
 </servlet>
<servlet-mapping>
    <servlet-name>ControllerServlet</servlet-name>
    <url-pattern>/ControllerServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>CollRestApi</servlet-name>
    <url-pattern>/or/*</url-pattern>
</servlet-mapping>

Rest Api Application :

public class RestApiApplication extends Application{

private Set<Object> singletons = new HashSet();
private Set<Class<?>> empty = new HashSet();

public RestApiApplication() {
    // ADD YOUR RESTFUL RESOURCES HERE
    this.singletons.add(new CollRestApi());
}

public Set<Class<?>> getClasses()
{
    return this.empty;
}

public Set<Object> getSingletons()
{
    return this.singletons;
}}

And CollRestApi.. is having exposed services..

   @Path("api")@Consumes({ "application/xml", "application/json" })@Produces({application/xml", "application/json" })public class CollRestApi {

/**
 * @return
 */
@GET
@Path("ab")
public Response do() {
    System.out.println("Inside the do Method.");

}}

Upvotes: 2

Views: 7773

Answers (3)

Stefan De Laet
Stefan De Laet

Reputation: 1419

I had the same exception, and fixed it like this:

Is it possible you have the resteasy**.jar libraries in a different location (e.g. the tomcat lib dir) than other resteasy-supporting libs like scannotation-1.0.3.jar (e.g. in your war file WEB-INF/lib) ?

In such a configuration your resteasy classes will start in a different classloader which does not see the scannotation-1.0.3.jar classes.

=> Try putting all resteasy jar files in either one of the locations (preferably your .war file).

Upvotes: 0

Fabian Fetzer
Fabian Fetzer

Reputation: 41

I just faced the same problem using maven and netbeans. The answer is to add the jboss maven repository to your pom.xml-file. Just adding <dependency>....</dependency>, e.g. by using netbeans maven browser, doesn't install the dependecies of resteasy.

<repositories>
        <repository>
            <id>jboss</id>
            <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
        </repository>
</repositories>

Upvotes: 4

Artem Nakolkin
Artem Nakolkin

Reputation: 66

Obviously, you need to add scannotation.jar to your classpath. RESTEasy 2.2.2.GA depends on scannotation-1.0.3 and javassist-3.12.1.GA.jar which you also need.

Upvotes: 4

Related Questions