title: Implement RESTful service in Java EE using J2EE Preview runtime in Eclipse
body: <p>These are the steps I followed to create a simple RESTful Web Service with Jax-RS in Eclipse IDE for Java EE.</p>
  
  <ul>
  <li>Create a new Dynamic Web Project (Name : TestExample)
  
  <ul>
  <li>Select target runtime as J2EE Preview </li>
  <li>Dynamic web module version : v3.1</li>
  <li>Configuration type : custom with following project facets 
  
  <ul>
  <li>Dynamic Web Module : v3.1</li>
  <li>Java : v1.8</li>
  <li>JAX-RS (REST Web Services) : v2.0</li>
  </ul></li>
  <li>Check "Generate web.xml deployment descriptor"</li>
  </ul></li>
  <li>Under Java Resources (in Project Explorer) create a new package (<code>my.test.example</code>) and a class under the same (<code>TestService</code>)</li>
  <li>Import external jar file <a href="http://www.java2s.com/Code/Jar/j/Downloadjavaxwsrsapi20jar.htm" rel="nofollow noreferrer"><code>javax.ws.rs-api-2.0.jar</code></a> and add it to build path to resolve <code>javax.ws.rs</code> import error</li>
  <li><p><code>TestService.java</code></p>
  
  <pre><code>package my.test.example;
  
  import javax.ws.rs.ApplicationPath;
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.core.Application;
  
  @Path("/MyTestService")
  @ApplicationPath("/resources")
  public class TestService extends Application {
  
      // http://localhost:8080/TestExample/resources/MyTestService/sayHello
      @GET
      @Path("/sayHello")
      public String getHelloMsg() {
          return "Hello World";
      }
  }
  </code></pre></li>
  <li><code>web.xml</code>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"&gt;
    &lt;display-name&gt;TestExample&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre></li>
  <li>Run the project</li>
  </ul>
  
  <p>Opening this url : <code>http://localhost:8080/TestExample/resources/MyTestService/sayHello</code> in a browser returns this :</p>
  
  <pre><code>HTTP ERROR 404 Not Found
  URI:    /TestExample/resources/MyTestService/sayHello
  STATUS: 404
  MESSAGE:    Not Found
  SERVLET:    default
  </code></pre>
  
  <p><strong>Console Output</strong></p>
  
  <pre><code>Starting preview server on port 8080
  
  Modules:
    TestExample (/TestExample)
  
  2020-05-21 11:45:45.175:INFO::main: Logging initialized @1815ms to org.eclipse.jetty.util.log.StdErrLog
  2020-05-21 11:45:45.894:INFO:oejs.Server:main: jetty-9.4.27.v20200227; built: 2020-03-02T14:40:42.212Z; git: a304fd9f351f337e7c0e2a7c28878dd536149c6c; jvm 1.8.0_171-b11
  2020-05-21 11:45:48.219:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /TestExample, did not find org.eclipse.jetty.jsp.JettyJspServlet
  2020-05-21 11:45:48.289:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
  2020-05-21 11:45:48.289:INFO:oejs.session:main: No SessionScavenger set, using defaults
  2020-05-21 11:45:48.299:INFO:oejs.session:main: node0 Scavenging every 600000ms
  2020-05-21 11:45:48.425:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@7d907bac{TestExample,/TestExample,file:///C:/.../wip/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/TestExample/,AVAILABLE}{C:/.../wip/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/TestExample}
  2020-05-21 11:45:48.489:INFO:oejs.AbstractConnector:main: Started ServerConnector@6ed3ef1{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
  2020-05-21 11:45:48.504:INFO:oejs.Server:main: Started @5150ms
  </code></pre>
  
  <p>The expected output would be <code>Hello World</code>. What am I missing here? </p>
  
  <p>The steps followed are based on a tutorial on Youtube : <a href="https://www.youtube.com/watch?v=dmMdLW92hBA" rel="nofollow noreferrer">Java EE Tutorial #18 - RESTful Web Services with Jax-RS</a>.</p>
  
  <p><strong>Eclipse Version</strong> : 2020-03 (4.15.0)</p>
  
  <p><strong>Note</strong>: I got it to work with GlassFish Runtime, however would still like to know why it doesn't work with J2EE Runtime.</p>
  
  <p>Project Structure in Eclipse :</p>
  
  <p><a href="https://i.stack.imgur.com/uRlYL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uRlYL.png" alt="project structure"></a></p>