RESTful web service with Jersey and Maven

In this tutorial we will create a simple RESTful web service with Jersey and Maven. The example code is available on Github.

1. Requirements

  • Eclipse EE 4.4.2 (important, make sure to use the EE version, otherwise you cannot adapt the Project Facets later on)
  • Apache Maven 3.3.3
  • M2E – useful Maven plugin for Eclipse
  • Tomcat 8
  • JDK 8

You can use other versions for Tomcat and the JDK, just make sure you adapt everything accordingly. The safest way is to use the same versions though.

2. Installation

Assuming JDK, Eclipse, Maven and Tomcat are installed correctly.

If you need help with installing either Maven or Tomcat, check out these tutorials.

If the preconditions are fullfiled, we continue with installing M2E. This Eclipse plugin helps us with creating and building Maven projects automatically.

  1. In Eclipse go to Help ⇒ Install new Software ⇒ Add and use the location: http://download.eclipse.org/technology/m2e/releases

    Eclipse Software Repository
    Enter some name and the location of the package

  2.  Press ok and click through the following Forms with Next.

    Eclipse Software Repository
    Select the required Packages

  3. After download and an Eclipse restart, M2E is successfully installed.

3. Create Maven Project

  1. In the Eclipse Project Explorer (on the left hand side) right click and select new project. Search for Maven and select Maven Project. Click Next.

    Create Maven Project
    Search for “maven” and select Maven Project

  2. Keep the properties in the next window and click Next.

    Create Maven Project Step 2
    Keep the predefined properties and click Next

  3. In the following window select Maven archetype maven-archetype-webapp and click Next.

    Create Maven Project Webapp
    Select Maven arcehtype maven-archetype-webapp

  4. Enter a group Id and artifact Id and click Next. Eclipse will generate the project structure.

    New Maven Webapp HelloWorld
    Enter group and artifact Id

  5. You will see the following project structure in the Project Explorer:

    Maven Eclipse Project Explorer
    Project Explorer after creating Maven project

  6. You probably see javax.servlet.http.HttpServlet” was not found on the Java Build Path.
  7. You have to add the Apache Tomcat servlet to the Java Build Path. Please follow this tutorial on how to integrate the Apache Tomcat dependencies into your project.

4. Adapt the pom.xml

  1. Open the pom.xml in your root folder and replace the content:

  2. Now some explanation for the pom.xml
    • <dependencies>: Libraries or jar files that are required. After a Maven project update (which we will perform later), Maven will download these libraries and add them to the Java Build Path.
    • <sourceDirectory>: Directory where Maven will find our packages and Java classes.
    • <plugins>: Addiontal information for Maven, e.g. compiler version

5. Adapt the web.xml

  1. Open the web.xml file located in your WEB-INF folder (srcmainwebappWEB-INF). You have to specify the servlet container, define start pages like index.php and locate the web service packages in your project.
  2. Replace the the web.xml with the following content:

  3. The welcome-file-list specifies which files are called per default, if available. The servlet and servlet-mapping specify the servlet container and the path to the servlet container. You can adapt display-name and servlet-name according to your requirements.
  4. Important: If you use different project or package etc., make sure the paths are adapted correctly. Especially <param-value>com.tutorialacademy.rest</param-value>.

6. Create a web service class

  1. Right click src/main and create a new folder called java
  2. Right click the new src/main/java source folder (below Java Resources), click on NewPackage. We call it com.tutorialacademy.rest.
  3. Right click the new package, click on NewClass. We call it RESTfulHelloWorld
  4. Copy the following code into the new class

  5. Ignore the code and import errors for now, we have to adapt the Maven project to retrieve missing dependencies.

7. Adapt the Maven project

  1. You should adapt the JDK and Dynamic Web Module Version in the Project Facets. Therefore, right click on your project and select Properties. Select Project Facets.

    Adapt Project Facets
    Adapt the Dynamic Web Module to version 3.1

  2. We adapted the  JDK to 1.8. You need at least JDK 1.7 to switch to the latest Dynamic Web Module version 3.1. If you are unfamiliar with this topic, please use the same versions to avoid complicating errors.
  3. You may not be able to adapt the Dynamic Web Module version. Deselect it, adapt the JDK version to 1.8 or 1.7 and hit apply. Select the desired Dynamic Web Module version and click apply again.
  4. You can select the JAX RS 1.1 as well. Anyways, this will adapt automatically after the update of the project in the next chapter.
  5. Depending on your selected version, Errors and Warnings may differ from this tutorial.

8. Update the Maven project

  1. Right click the project and select Maven Update Project. You can press ALT + F5 as shortcut.

    Update Maven Project
    Select your project and click OK

  2. Now Maven will download missing dependencies, adapt the project structure according to the pom.xml.
  3. Important: Copy your web.xml into WebContent/WEB-INF folder. You can delete the index.js.
  4. Your project structure should now look similar to this:

    Project Explorer Dynamic Web Module 3.1
    Compare if you have a similar project structure

9. Run Maven Build

  1. Right click your project and select Run As:

    Run as Maven Configuration
    Select run as Maven Build (6)

  2. Add clean install to the goals and click Apply and then Run:

    Maven Clean Install Goals
    Clean the project and rebuild it

  3. Now Maven generated a war file in the target folder:

    aven Clean Install Target
    Check if you have generated a war file and or error messages in the console

  4. If you do not see any errors but “[INFO] BUILD SUCCESS”, we can start an run our project on the Tomcat server.

10. Run the RESTful project on Server

You can use the internal Eclipse web browser and Tomcat runtime or deploy it yourself.

  1. Deployment in Eclipse:
    1. Right click your project and select Run As Run on Server
    2. Eclipse will open the internal web browser, but we have to adapt the URL to “http://localhost:8080/helloworld/rest/”

      RESTful Webservice Running
      You should see the Hello World message in your browser

  2. Deployment in Tomcat directly:
    1. Copy the “helloworld-0.0.1-SNAPSHOT.war” file into your %CATALINA_HOME%/webapps folder.
    2. Go to the command line (Winkey + R) and enter: %CATALINA_HOME%\bin\startup.bat
    3. Enter “http://localhost:8080/helloworld-0.0.1-SNAPSHOT/rest/” in your web browser:

      RESTful Webservice Running Browser
      Check if you see the Hello World message

  3. Now you created a RESTful web service using Maven and Tomcat.

If you have errors, exceptions or other problems feel free to comment and ask.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

13 Thoughts to “RESTful web service with Jersey and Maven”

  1. cordial

    hey,

    Thanks for the tutorial. I am having some issues running the service though, I always receive a 404 error when i hit the endpoint.

    I’m using eclipse neon, jdk8, tomcat 8.5.

    Here is my tomcat console output –
    http://pastie.org/pastes/10976623

    Here is my java resource class –
    http://pastie.org/pastes/10976618

    Here is my web.xml file –
    http://pastie.org/10976693

    Here is my pom.xml –
    http://pastie.org/10976695

    I have also tried fiddling with the tomcat deploy destination (between webapps and wtpwebapps) but that didnt help. The webapps folder has a ‘form-builder’ dir in it and as you can see from the tomcat trace, it seems to recognise & expand it (when I hit localhost).

    Can you see where I have gone wrong (i’m hoping I’ve made a stupid error).

    cheers
    David

  2. go

    Hi,

    I find the tutorial very useful; I am used to create Restful services in Eclipse with Jersey but without Maven. Now I want to incroporate the use of Maven. I installed Eclipse Neon JavaEE (Maven included) and Tomcat 8.

    My problem is in the step “Update the Maven project”; JDK 1.8 and Jersey 1.1 are ok, but when selecting Dynamic Web Module to version 3.1 it raises the error “Cannot change version of the project facet Dynamic Web Module to 3.1” (it only accepts version 2.3)

    Any help is really welcomed.
    Thanks!!

    1. Hi, sorry for the late answer.

      Please check chapter “7. Adapt the Maven project” bullet 3.

      It should work if you deselect it, hit apply and then reselect the 3.1 Web Module.

      Malte

  3. kin11

    I have done everything correctly,I think.Yet I get a HTTP 404 error.Could you please help ?
    type Status report

    message /helloworld/rest/

    description The requested resource is not available.
    Does this mean that my server is functional but I cannot access the resource ? And if so,why ?

    1. Hey,

      yes 404 means server is running but cannot find the requested resource.
      Did you adapt the web.xml? It´s most likely a path / configuration problem.
      Please post more information / logs / web.xml etc. otherwise its hard to help properly.

      1. kin11

        Thanks for the prompt reply.I have used the same web.xml as you,nevertheless posting it.

        helloworld

        index.html
        index.htm
        index.jsp
        default.html
        default.htm
        default.jsp

        helloworld
        com.sun.jersey.spi.container.servlet.ServletContainer

        com.sun.jersey.config.property.packages
        com.tutorialacademy.rest

        1

        helloworld
        /rest/*

        pom.xml(smae as yours) :

        4.0.0
        com.tutorialacademy.rest
        helloworld
        war
        0.0.1-SNAPSHOT
        helloworld Maven Webapp
        http://maven.apache.org

        UTF-8

        maven2-repository.java.net
        Java.net Repository for Maven
        http://download.java.net/maven/2/
        default

        junit
        junit
        3.8.1
        test

        com.sun.jersey
        jersey-server
        1.9

        src/main/java

        maven-war-plugin
        2.4

        WebContent
        false

        maven-compiler-plugin
        3.1

        1.8
        1.8

        Console log : Jun 12, 2016 5:33:35 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
        WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:TEST’ did not find a matching property.
        Jun 12, 2016 5:33:35 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
        WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:helloworld’ did not find a matching property.
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: Server version: Apache Tomcat/8.0.35
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: Server built: May 11 2016 21:57:08 UTC
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: Server number: 8.0.35.0
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: OS Name: Windows 10
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: OS Version: 10.0
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: Architecture: amd64
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: Java Home: C:\Program Files\Java\jre1.8.0_91
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: JVM Version: 1.8.0_91-b15
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: JVM Vendor: Oracle Corporation
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: CATALINA_BASE: C:\Users\lenovo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: CATALINA_HOME: C:\apache-tomcat-8.0.35
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: Command line argument: -Dcatalina.base=C:\Users\lenovo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: Command line argument: -Dcatalina.home=C:\apache-tomcat-8.0.35
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: Command line argument: -Dwtp.deploy=C:\Users\lenovo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: Command line argument: -Djava.endorsed.dirs=C:\apache-tomcat-8.0.35\endorsed
        Jun 12, 2016 5:33:35 PM org.apache.catalina.startup.VersionLoggerListener log
        INFO: Command line argument: -Dfile.encoding=Cp1252
        Jun 12, 2016 5:33:35 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
        INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_91\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_91/bin/server;C:/Program Files/Java/jre1.8.0_91/bin;C:/Program Files/Java/jre1.8.0_91/lib/amd64;C:\Program Files\Python36\Scripts\;C:\Program Files\Python36\;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\AMD\ATI.ACE\Core-Static;C:\Program Files\Java\jdk1.8.0_77\bin;C:\Users\lenovo\Downloads\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;E:\eclipse;;.
        Jun 12, 2016 5:33:35 PM org.apache.coyote.AbstractProtocol init
        INFO: Initializing ProtocolHandler [“http-nio-9999”]
        Jun 12, 2016 5:33:36 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
        INFO: Using a shared selector for servlet write/read
        Jun 12, 2016 5:33:36 PM org.apache.coyote.AbstractProtocol init
        INFO: Initializing ProtocolHandler [“ajp-nio-8009”]
        Jun 12, 2016 5:33:36 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
        INFO: Using a shared selector for servlet write/read
        Jun 12, 2016 5:33:36 PM org.apache.catalina.startup.Catalina load
        INFO: Initialization processed in 1410 ms
        Jun 12, 2016 5:33:36 PM org.apache.catalina.core.StandardService startInternal
        INFO: Starting service Catalina
        Jun 12, 2016 5:33:36 PM org.apache.catalina.core.StandardEngine startInternal
        INFO: Starting Servlet Engine: Apache Tomcat/8.0.35
        Jun 12, 2016 5:33:36 PM org.apache.jasper.servlet.TldScanner scanJars
        INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
        Jun 12, 2016 5:33:37 PM org.apache.coyote.AbstractProtocol start
        INFO: Starting ProtocolHandler [“http-nio-9999”]
        Jun 12, 2016 5:33:37 PM org.apache.coyote.AbstractProtocol start
        INFO: Starting ProtocolHandler [“ajp-nio-8009”]
        Jun 12, 2016 5:33:37 PM org.apache.catalina.startup.Catalina start
        INFO: Server startup in 890 ms

        1. Hey,
          how do you deploy the war file? Do you use Eclipse or deploy it directly in tomcat?
          From your log it seems that no .war file is deployed to the tomcat:

          12-Jun-2016 14:19:49.344 INFO [localhost-startStop-1] com.sun.jersey.api.core.PackagesResourceConfig.init Scanning for root resource and provider classes in the packages:
          com.tutorialacademy.rest
          12-Jun-2016 14:19:49.359 INFO [localhost-startStop-1] com.sun.jersey.api.core.ScanningResourceConfig.logClasses Root resource classes found:
          class com.tutorialacademy.rest.RESTfulHelloWorld
          12-Jun-2016 14:19:49.360 INFO [localhost-startStop-1] com.sun.jersey.api.core.ScanningResourceConfig.init No provider classes found.
          12-Jun-2016 14:19:49.411 INFO [localhost-startStop-1] com.sun.jersey.server.impl.application.WebApplicationImpl._initiate Initiating Jersey application, version ‘Jersey: 1.9 09/02/2011 11:17 AM’
          12-Jun-2016 14:19:49.680 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive D:\Developer\Tomcat\apache-tomcat-8.0.22\webapps\helloworld-0.0.1-SNAPSHOT.war has finished in 695 ms
          12-Jun-2016 14:19:49.684 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\Developer\Tomcat\apache-tomcat-8.0.22\webapps\docs
          12-Jun-2016 14:19:49.734 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\Developer\Tomcat\apache-tomcat-8.0.22\webapps\docs has finished in 50 ms
          12-Jun-2016 14:19:49.735 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\Developer\Tomcat\apache-tomcat-8.0.22\webapps\examples
          12-Jun-2016 14:19:50.080 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\Developer\Tomcat\apache-tomcat-8.0.22\webapps\examples has finished in 345 ms
          12-Jun-2016 14:19:50.080 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\Developer\Tomcat\apache-tomcat-8.0.22\webapps\manager
          12-Jun-2016 14:19:50.133 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\Developer\Tomcat\apache-tomcat-8.0.22\webapps\manager has finished in 53 ms
          12-Jun-2016 14:19:50.195 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\Developer\Tomcat\apache-tomcat-8.0.22\webapps\ROOT
          12-Jun-2016 14:19:50.214 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\Developer\Tomcat\apache-tomcat-8.0.22\webapps\ROOT has finished in 19 ms
          12-Jun-2016 14:19:50.227 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [“http-nio-8080”]
          12-Jun-2016 14:19:50.231 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [“ajp-nio-8009”]
          12-Jun-2016 14:19:50.233 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1291 ms

          That is the end from my startup log. Tomcat scans for the root resource class and deploys the war files located in the webapps folder.
          Thats why you get the 404, because there is nothing mapped to the path your are calling.

          If you directly copied the pom.xml and web.xml please check your folder structure. Is your package name com.tutorialacademy.rest etc.?

          I can send you the war file or project via email if you like, then you try if that works and compare.

          1. kin11

            Hi! I noticed that my project wasi n src/{Project-name}/java,so I deleted it and made a fresh one in src/ain/Java. I am using Eclipse to deploy the .war file.But now on accessing http://localhost:9999/helloworld/rest,I get the HTTP Status 500.Below is my log :

            Jun 12, 2016 7:18:00 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
            WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:TEST’ did not find a matching property.
            Jun 12, 2016 7:18:00 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
            WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:helloworld’ did not find a matching property.
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: Server version: Apache Tomcat/8.0.35
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: Server built: May 11 2016 21:57:08 UTC
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: Server number: 8.0.35.0
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: OS Name: Windows 10
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: OS Version: 10.0
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: Architecture: amd64
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: Java Home: C:\Program Files\Java\jdk1.8.0_77\jre
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: JVM Version: 1.8.0_77-b03
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: JVM Vendor: Oracle Corporation
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: CATALINA_BASE: C:\Users\lenovo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: CATALINA_HOME: C:\apache-tomcat-8.0.35
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: Command line argument: -Dcatalina.base=C:\Users\lenovo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: Command line argument: -Dcatalina.home=C:\apache-tomcat-8.0.35
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: Command line argument: -Dwtp.deploy=C:\Users\lenovo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: Command line argument: -Djava.endorsed.dirs=C:\apache-tomcat-8.0.35\endorsed
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.VersionLoggerListener log
            INFO: Command line argument: -Dfile.encoding=Cp1252
            Jun 12, 2016 7:18:00 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
            INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_77\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_91/bin/server;C:/Program Files/Java/jre1.8.0_91/bin;C:/Program Files/Java/jre1.8.0_91/lib/amd64;C:\Program Files\Python36\Scripts\;C:\Program Files\Python36\;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\AMD\ATI.ACE\Core-Static;C:\Program Files\Java\jdk1.8.0_77\bin;C:\Users\lenovo\Downloads\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;E:\eclipse;;.
            Jun 12, 2016 7:18:00 PM org.apache.coyote.AbstractProtocol init
            INFO: Initializing ProtocolHandler [“http-nio-9999”]
            Jun 12, 2016 7:18:00 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
            INFO: Using a shared selector for servlet write/read
            Jun 12, 2016 7:18:00 PM org.apache.coyote.AbstractProtocol init
            INFO: Initializing ProtocolHandler [“ajp-nio-8009”]
            Jun 12, 2016 7:18:00 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
            INFO: Using a shared selector for servlet write/read
            Jun 12, 2016 7:18:00 PM org.apache.catalina.startup.Catalina load
            INFO: Initialization processed in 1124 ms
            Jun 12, 2016 7:18:00 PM org.apache.catalina.core.StandardService startInternal
            INFO: Starting service Catalina
            Jun 12, 2016 7:18:00 PM org.apache.catalina.core.StandardEngine startInternal
            INFO: Starting Servlet Engine: Apache Tomcat/8.0.35
            Jun 12, 2016 7:18:01 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
            INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [103] milliseconds.
            Jun 12, 2016 7:18:01 PM org.apache.jasper.servlet.TldScanner scanJars
            INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
            Jun 12, 2016 7:18:01 PM com.sun.jersey.api.core.PackagesResourceConfig init
            INFO: Scanning for root resource and provider classes in the packages:
            com.tutorialacademy.rest
            Jun 12, 2016 7:18:02 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
            INFO: Initiating Jersey application, version ‘Jersey: 1.9 09/02/2011 11:17 AM’
            Jun 12, 2016 7:18:02 PM com.sun.jersey.server.impl.application.RootResourceUriRules
            SEVERE: The ResourceConfig instance does not contain any root resource classes.
            Jun 12, 2016 7:18:02 PM org.apache.catalina.core.ApplicationContext log
            SEVERE: StandardWrapper.Throwable
            com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
            at com.sun.jersey.server.impl.application.RootResourceUriRules.(RootResourceUriRules.java:99)
            at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
            at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
            at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
            at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
            at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
            at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
            at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
            at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
            at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
            at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
            at javax.servlet.GenericServlet.init(GenericServlet.java:158)
            at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238)
            at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1151)
            at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038)
            at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4998)
            at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
            at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
            at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
            at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:745)

            Jun 12, 2016 7:18:02 PM org.apache.catalina.core.StandardContext loadOnStartup
            SEVERE: Servlet [helloworld] in web application [/helloworld] threw load() exception
            com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
            at com.sun.jersey.server.impl.application.RootResourceUriRules.(RootResourceUriRules.java:99)
            at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
            at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
            at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
            at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
            at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
            at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
            at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
            at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
            at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
            at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
            at javax.servlet.GenericServlet.init(GenericServlet.java:158)
            at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238)
            at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1151)
            at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038)
            at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4998)
            at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
            at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
            at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
            at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:745)

            Jun 12, 2016 7:18:02 PM org.apache.coyote.AbstractProtocol start
            INFO: Starting ProtocolHandler [“http-nio-9999”]
            Jun 12, 2016 7:18:02 PM org.apache.coyote.AbstractProtocol start
            INFO: Starting ProtocolHandler [“ajp-nio-8009”]
            Jun 12, 2016 7:18:02 PM org.apache.catalina.startup.Catalina start
            INFO: Server startup in 1848 ms
            Jun 12, 2016 7:18:13 PM com.sun.jersey.api.core.PackagesResourceConfig init
            INFO: Scanning for root resource and provider classes in the packages:
            com.tutorialacademy.rest
            Jun 12, 2016 7:18:13 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
            INFO: Initiating Jersey application, version ‘Jersey: 1.9 09/02/2011 11:17 AM’
            Jun 12, 2016 7:18:13 PM com.sun.jersey.server.impl.application.RootResourceUriRules
            SEVERE: The ResourceConfig instance does not contain any root resource classes.
            Jun 12, 2016 7:18:13 PM org.apache.catalina.core.ApplicationContext log
            SEVERE: StandardWrapper.Throwable
            com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
            at com.sun.jersey.server.impl.application.RootResourceUriRules.(RootResourceUriRules.java:99)
            at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
            at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
            at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
            at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
            at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
            at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
            at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
            at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
            at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
            at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
            at javax.servlet.GenericServlet.init(GenericServlet.java:158)
            at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238)
            at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1151)
            at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:828)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
            at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
            at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
            at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
            at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
            at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
            at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            at java.lang.Thread.run(Thread.java:745)

            Jun 12, 2016 7:18:13 PM org.apache.catalina.core.StandardWrapperValve invoke
            SEVERE: Allocate exception for servlet helloworld
            com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
            at com.sun.jersey.server.impl.application.RootResourceUriRules.(RootResourceUriRules.java:99)
            at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
            at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
            at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
            at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
            at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
            at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
            at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
            at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
            at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
            at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
            at javax.servlet.GenericServlet.init(GenericServlet.java:158)
            at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238)
            at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1151)
            at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:828)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
            at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
            at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
            at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
            at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
            at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
            at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            at java.lang.Thread.run(Thread.java:745)
            To my understanding,this happens because no class can be found to be executed as a web service.How do I fix this ?
            Also,you mention the .war file being in webapps folder.My war file is at workspace/helloworld/target.Your help is greatly appreciated.

          2. Hey,
            now tomcat searches in the right folder:

            Jun 12, 2016 7:18:13 PM com.sun.jersey.api.core.PackagesResourceConfig init
            INFO: Scanning for root resource and provider classes in the packages:
            com.tutorialacademy.rest

            There are exceptions because no root resource class can be found (RESTfulHelloWorld in the blog example):
            1. Make sure the class is located in the correct package (which you specified in web.xml. Blog: com/tutorialacademy/rest )
            2. Make sure the class is compiled properly (check if it is available in workspace/helloworld/target/classes/com/tutorialacademy/rest as .class file and finally in the warfile itself: workspace/helloworld/target/helloworld-0.0.1-SNAPSHOT/WEB-INF/classes/com/tutorialacademy/rest)
            3. Make sure you have the entry point annotation in the main class (RESTfulHelloWorld: @Path(“/”) )

            Do a maven project clean and rebuild to remove artefacts.

            For now it doesnt work because there is something messed up with your folders/packages and the config path. Please have a look at the screenshots of my eclipse project to make sure your path configuration etc. is correct, or adapt accordingly.

            Your warfile is correctly placed if you deploy from eclipse. Anyhow, in production you will deploy a warfile to tomcat directly (which you copy into the webapps folder of tomcat).

            Hope this helps.

  4. bpeyredieu

    10:12:27,247 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.deployment.unit.”totoRest.war”.POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit.”totoRest.war”.POST_MODULE: JBAS018733: N’a pas pu traiter la phase POST_MODULE de deployment “totoRest.war”
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [jboss-as-server-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1980) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1913) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_51]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_51]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_51]
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011232: Une seule classe Application JAX-RS trouvée. com.sun.jersey.api.core.ScanningResourceConfig com.sun.jersey.api.core.PackagesResourceConfig com.sun.jersey.api.core.DefaultResourceConfig com.sun.jersey.api.core.ClasspathResourceConfig com.sun.jersey.api.core.ApplicationAdapter com.sun.jersey.server.impl.application.DeferredResourceConfig com.sun.jersey.api.core.WebAppResourceConfig com.sun.jersey.api.core.ClassNamesResourceConfig com.sun.jersey.api.core.ResourceConfig
    at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scan(JaxrsScanningProcessor.java:206)
    at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:104)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [jboss-as-server-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    … 5 more

    1. “Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011232: Une seule classe Application JAX-RS trouvée”

      Please check that no other JAX-RS implementation is listed in the classpath. Can you post your pom file / classpath?

Leave a Reply