在Tomcat上使用RESTeasy [英] Using RESTeasy on Tomcat

查看:127
本文介绍了在Tomcat上使用RESTeasy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是RESTful Web服务的新手.我的一位客户给我提供了一些易于实现的方法,这些方法可以在我的项目中使用.我正在项目中使用apache tomcat服务器.这些方法可以在apache tomcat服务器上运行吗?是否??

I am new to restful web services.One of my client given me some methods with resteasy implementation those methods i have use in my project.I am using apache tomcat server in my project.can these methods will run on apache tomcat server or not???

推荐答案

是的.您需要添加RESTeasy实施jar/依赖项.

Yes it's possible. You need to add the RESTeasy implementation jars/dependencies.

对于Maven(resteasy.version == 3.0.9.Final)

For Maven (resteasy.version == 3.0.9.Final)

<!-- Basic support -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<!-- Servlet pluggability support -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-servlet-initializer</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<!-- JSON/POJO support -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson2-provider</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<!-- REST Client support -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>${resteasy.version}</version>
</dependency>

您可以在下面看到Maven依赖项引入的所有jar和可传递jar(如果您未使用Maven).

You can see all the jars and transitive jars the Maven dependencies pull in (if you are not using Maven) below.

您可以在所有罐子的此处下载.另外,还请随身携带文档.我没有包括发行版附带的所有依赖项.其他功能需要一些依赖关系.您可以根据需要添加所有jar(来自发行版),但是我只是向您展示所需的基础知识.

You can download the distribution here, which comes with all the jars. Also keep the Documentation handy. I didn't include all the dependencies that come with the distribution. Some dependencies are needed for other features. You could add all the jars (from the distribution) if you want, but I'm just showing you the basics of what it needed.

您还应该注意该版本. 3.x和2.x系列工作于不同的API,因此您可能需要准确地确定需要哪个API.我提供的链接包含所有版本的发行版和文档.为了这个答案,我只使用了3.0.9.Final.

You should also pay attention to the version. The 3.x and 2.x series work of different APIs, so you may need to figure out exactly which one you need. The links I provided contain distributions and documentation for all versions. For the sake of this answer, I just used 3.0.9.Final.

另一件事,发行版附带了一堆示例,可能会派上用场.尽管所有示例都需要Maven.

Another thing, the distribution comes with a bunch of example that will probably come in handy. Though all the examples require Maven.

有了上述jar/依赖项,您只需使用

With the above jars/dependencies, you can get a simple app up and running, simply with

@ApplicationPath("/rest")
public class WebConfig extends Application {
}

@Path("/simple")
public class SimpleResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getTest() {
        return "Hello REST World!";
    }
}

不需要额外的(web.xml)配置.使用带有@ApplicationPath批注的空Application类,所有带有@Path的类都将注册为资源类. resteasy-servlet-initializer使之成为可能,它使用了servlet可插拔机制.

No extra (web.xml) configuration is needed. With the empty Application class with the @ApplicationPath annotation, all classes with @Path will be registered as resource classes. This is made possible by the resteasy-servlet-initializer, which works off the servlet pluggability mechanism.

在图像中,javaee-web-api jar不应位于其中.当我尝试创建映像时,我必须已经创建了一个新的maven Web项目.

In the image, the javaee-web-api jar should not be in there. I must've created a new maven web project that included that in there when I was trying to create the image.

这篇关于在Tomcat上使用RESTeasy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆