Search code examples
javarestjbossresteasy

RESTEasy with Apache Ant


We use Apache Ant for building our application and I am trying to expose some of the services using REST. I am using RESTEasy as the implementation. I have downloaded resteasy-jaxrs-2.3.5.final.jar and added it in classpath of my current project. I have also made entries in web.xml and my web.xml looks like this:

<!DOCTYPE web-app PUBLIC 
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Restful Web Application</display-name>

    <!-- Auto scan REST service -->
    <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>true</param-value>
    </context-param>

    <!-- this need same with resteasy servlet url-pattern -->
    <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/rest</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>

But when I am writing an endpoint class, the REST annotations like @Path are not found and consequently I was not able to annotate my class with any REST annotations. Can anyone suggest what I need to do?


Solution

  • @Path comes from jaxrs-api jar. You need to make sure that your ANT build is pulling all the dependencies while pulling the resteasy-jaxrs-2.3.5.final.jar. If not you need to update your ANT build file with all the dependencies required to write/compile/build the archive.