4

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

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
Sujithrao
  • 789
  • 3
  • 12
  • 27

1 Answers1

10

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

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>

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

enter image description here

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.

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.

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


UPDATE

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!";
    }
}

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.


EDIT

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.

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • 1
    Thanks for your response i am not created a maven project .i have created a javaEE web application in that i have added all the require jars but when i run the project its giving me the following error. – Sujithrao Jun 29 '15 at 04:29
  • SEVERE: Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap java.lang.ClassCastException: org.glassfish.jersey.server.internal.RuntimeDelegateImpl cannot be cast to org.jboss.resteasy.spi.ResteasyProviderFactory SEVERE: Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.spring.SpringContextLoaderListener java.lang.RuntimeException: RESTeasy Provider Factory is null, do you have the ResteasyBootstrap listener configured? – Sujithrao Jun 29 '15 at 04:31
  • You can not use all the Java EE functionality in vanilla Tomcat. It is only a Servlet container, and doesn't provider the full EE stack implementation. As such, a JAX-RS implementation is also not included, so we need to include it ourselves, as I am showing you here in my answer. Any other EE functionality like CDI and EJB is also not included in vanilla Tomcat – Paul Samsotha Jun 29 '15 at 04:32
  • It looks like the application is trying to use Spring support, which is in another module (included in the distribution). You can try to add all the jars from the distribution. That's a lot of Jars. I highly recommend using Maven. If you don't know it, take a day to learn it. It shouldn't take long to learn the basic functionality of dependency management. Then look at the spring example in the distribution – Paul Samsotha Jun 29 '15 at 04:36
  • my project is already deployed in javaEE web application now the restful added to my project is it easy to change my entire project to maven web application could you please help me out – Sujithrao Jun 29 '15 at 04:41
  • Not sure how easy that will be, if it's even possible. It might be but I am not sure. Like I said, the distribution comes with example you can just load into your IDE. I cannot teach you Maven. If you don't understand a little about Maven, then you will have trouble navigating the project. That's why I said you should take some time to learn it. It shouldn't take long. Then learn some of the basic support your IDE has for Maven. The projects can be loaded straight into your IDE if the IDE has Maven support. From there, you can just look at spring project, build it, and see all the jars it... – Paul Samsotha Jun 29 '15 at 04:46
  • is it now possible to run the restful methods with javaEE web application environment? – Sujithrao Jun 29 '15 at 04:46
  • ...then you can add those jars to your main project (if you can't convert it to a Maven project) – Paul Samsotha Jun 29 '15 at 04:47
  • You should be able to. But I can't really help any further without more information. – Paul Samsotha Jun 29 '15 at 04:48
  • ok finally one more question for sure we can run the jboss resteasy sevices implementation methods in apache tomcat server i am getting confusion here only whether we can run with apache tomcat server or we need to use jboss application server only just clarify about this? thanks for response – Sujithrao Jun 29 '15 at 04:58
  • Yes. You can run it in any servlet container. – Paul Samsotha Jun 29 '15 at 05:01
  • Have a look at [this post](http://stackoverflow.com/a/28129465/2587435). You can configure the application without any web.xml. Just using Java code. With all the jars I posted above, use the method from the link, you should be able to run a simple application. See also [here](http://stackoverflow.com/a/27297884/2587435) – Paul Samsotha Jun 29 '15 at 05:21
  • hey i tried but getting the following exception now..SEVERE: Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap java.lang.NoClassDefFoundError: javax/ws/rs/core/Link$Builder – Sujithrao Jun 29 '15 at 10:46
  • Please post another question showing your complete attempt, providing enough information to help you debug the problem. I have provided enough in my answer to get a simple app up and running. – Paul Samsotha Jun 29 '15 at 11:06
  • i have posted another question .can you please have a look and tell me that what is the mistake i have done? – Sujithrao Jun 29 '15 at 11:16