title: Hello world of RESTful based on Jersey and Jetty
body: <p>I'm following <a href="https://jersey.java.net/documentation/latest/deployment.html" rel="nofollow">this guide</a> to build my hello world web service and get kind of stuck, here are my codes:</p>
  
  <p><code>MyResource.java:</code></p>
  
  <pre><code>package com.example;
  
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  
  @Path("myresource")
  public class MyResource {
      @GET
      @Produces("text/plain")
      public String getIt() {
          return "Got it!";
      }
  }
  </code></pre>
  
  <p><code>pom.xml:</code></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;groupId&gt;ts&lt;/groupId&gt;
  &lt;artifactId&gt;mtest&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;mtest Maven Webapp&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-container-jetty-http&lt;/artifactId&gt;
          &lt;version&gt;2.19&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-container-jetty-servlet&lt;/artifactId&gt;
          &lt;version&gt;2.19&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  &lt;build&gt;
      &lt;finalName&gt;mtest&lt;/finalName&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;jetty-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;9.3.0.M1&lt;/version&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p><code>web.xml:</code></p>
  
  <pre><code>&lt;web-app version="3.0"
       xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  
  &lt;!-- Servlet declaration can be omitted in which case
       it would be automatically added by Jersey --&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;javax.ws.rs.core.Application&lt;/servlet-name&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;javax.ws.rs.core.Application&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/myresource/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p></p>
  
  <p>Now my problems are:</p>
  
  <ol>
  <li>After launching Jetty, I can get a hello world of my jsp from <code>http://localhost:8080/</code>, but <code>http://localhost:8080/myresource</code> returns 404</li>
  <li>Intellij complains <code>Element web-app must be declared</code></li>
  </ol>