首页 > 解决方案 > RESTEasy 与 Apache Ant

问题描述

我们使用 Apache Ant 构建我们的应用程序,我正在尝试使用 REST 公开一些服务。我使用 RESTEasy 作为实现。我已经下载了 resteasy-jaxrs-2.3.5.final.jar 并将其添加到我当前项目的类路径中。我还在 web.xml 中创建了条目,我的 web.xml 看起来像这样:

<!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>

但是当我编写端点类时,找不到像 @Path 这样的 REST 注释,因此我无法使用任何 REST 注释来注释我的类。谁能建议我需要做什么?

标签: javarestjbossresteasy

解决方案


@Path来自jaxrs-api罐子。您需要确保您的 ANT 构建在拉动resteasy-jaxrs-2.3.5.final.jar. 如果不是,您需要使用编写/编译/构建存档所需的所有依赖项来更新您的 ANT 构建文件。


推荐阅读