title: Maven - Restful web service - Jersey - compilation error - package javax.ws.rs does not exist
body: <p>The correct solution for this issue is still not available in the internet threads.
  I have a maven project in eclipse for Jersey RESTFul Web Services. So, jersey required below libraries (21 nos.) are copied into project --> WEB-INF --> lib folder and project build path.</p>
  
  <pre><code>aopalliance-repackaged-2.4.0-b34.jar
   asm-debug-all-5.0.4.jar
   hk2-api-2.4.0-b34.jar 
   hk2-locator-2.4.0-b34.jar
   hk2-utils-2.4.0-b34.jar 
   javassist-3.18.1-GA.jar
   javax.annotation-api-1.2.jar
   javax.inject-2.4.0-b34.jar
   javax.servlet-api-3.0.1.jar 
   javax.ws.rs-api-2.0.1.jar
   jaxb-api-2.2.7.jar jersey-client.jar
   jersey-common.jar
   jersey-container-servlet.jar 
   jersey-container-servlet-core.jar
   jersey-guava-2.23.1.jar 
   jersey-media-jaxb.jar jersey-server.jar
   org.osgi.core-4.2.0.jar 
   osgi-resource-locator-1.0.1.jar
   persistence-api-1.0.jar 
   validation-api-1.1.0.Final.jar
  </code></pre>
  
  <p>When i export this project as WAR file and deployed in Tomcat, the service is accessible. But the actual requirement is to run this service in WebLogic server where the same WAR file is not working. So, I has to create the WAR file using maven not by just export as WAR file.</p>
  
  <p>Below are the steps i did.</p>
  
  <p>In Eclipse -->Project --> Right click --> run as Maven build --> clean install --> run</p>
  
  <p>it's still throwing the below compilation error.</p>
  
  <p>[ERROR] COMPILATION ERROR : 
  [INFO] -------------------------------------------------------------
  [ERROR] /Users/karthik/Documents/workspace/Apple_DownloadFileWS/src/com/apple/downloadws/DownloadService.java:[6,19] package javax.ws.rs does not exist
  [ERROR] /Users/karthik/Documents/workspace/Apple_DownloadFileWS/src/com/apple/downloadws/DownloadService.java:[7,19] package javax.ws.rs does not exist
  [ERROR] /Users/karthik/Documents/workspace/Apple_DownloadFileWS/src/com/apple/downloadws/DownloadService.java:[8,19] package javax.ws.rs does not exist
  [ERROR] /Users/karthik/Documents/workspace/Apple_DownloadFileWS/src/com/apple/downloadws/DownloadService.java:[9,24] package javax.ws.rs.core does not exist
  [ERROR] /Users/karthik/Documents/workspace/Apple_DownloadFileWS/src/com/apple/downloadws/DownloadService.java:[10,24] package javax.ws.rs.core does not exist
  [ERROR] /Users/karthik/Documents/workspace/Apple_DownloadFileWS/src/com/apple/downloadws/DownloadService.java:[11,33] package javax.ws.rs.core.Response does not exist
  [ERROR] /Users/karthik/Documents/workspace/Apple_DownloadFileWS/src/com/apple/downloadws/DownloadService.java:[23,2] cannot find symbol
  symbol: class Path
  [ERROR] /Users/karthik/Documents/workspace/Apple_DownloadFileWS/src/com/apple/downloadws/DownloadService.java:[31,12] cannot find symbol
  symbol  : class Response </p>
  
  <p>Here is my pom.xml:</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/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;Apple_DownloadFileWS&lt;/groupId&gt;
      &lt;artifactId&gt;Apple_DownloadFileWS&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;name&gt;Apple_DownloadFileWS&lt;/name&gt;
      &lt;build&gt;
          &lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.6&lt;/source&gt;
                      &lt;target&gt;1.6&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;warSourceDirectory&gt;WebContent&lt;/warSourceDirectory&gt;
                      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-client&lt;/artifactId&gt;
                  &lt;version&gt;2.23.1&lt;/version&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-common&lt;/artifactId&gt;
                  &lt;version&gt;2.11&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet-core --&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-container-servlet-core&lt;/artifactId&gt;
                  &lt;version&gt;2.23&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet --&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-container-servlet&lt;/artifactId&gt;
                  &lt;version&gt;2.23&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;!-- https://mvnrepository.com/artifact/org.glassfish.jersey.bundles.repackaged/jersey-guava --&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.bundles.repackaged&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-guava&lt;/artifactId&gt;
                  &lt;version&gt;2.23.1&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-jaxb --&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-media-jaxb&lt;/artifactId&gt;
                  &lt;version&gt;2.23&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson --&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-media-json-jackson&lt;/artifactId&gt;
                  &lt;version&gt;2.23&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
                  &lt;artifactId&gt;javax.ws.rs-api&lt;/artifactId&gt;
                  &lt;version&gt;2.0.1&lt;/version&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;javax&lt;/groupId&gt;
                  &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
                  &lt;version&gt;6.0&lt;/version&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
  
  
              &lt;dependency&gt;
      &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
      &lt;artifactId&gt;jsr311-api&lt;/artifactId&gt;
      &lt;version&gt;1.1.1&lt;/version&gt;
  &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>Web.xml:</p>
  
  <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://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;Apple_DownloadFileWS&lt;/display-name&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
        &lt;param-value&gt;com.apple.downloadws&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Service class:</p>
  
  <pre><code>package com.apple.downloadws;
  
  import java.io.File;
  import java.util.logging.Logger;
  
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces; 
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;  
  import javax.ws.rs.core.Response.ResponseBuilder;  
  
  // Plain old Java Object it does not extend as class or implements 
  // an interface
  
  // The class registers its methods for the HTTP GET request using the @GET annotation. 
  // Using the @Produces annotation, it defines that it can deliver several MIME types,
  // text, XML and HTML. 
  
  // The browser requests per default the HTML MIME type.
  
  //Sets the path to base URL + /hello
  @Path("/downloadservice")
  public class DownloadService {
  
    // This method is called to send the output txt file to download...
      private static final String FILE_PATH = "/ngs/app/alect/test";  
      @GET   
      @Path("/txt")  
      @Produces("text/plain")    
      public Response getTextFile() {  
          File file = new File(FILE_PATH);  
          Logger.getLogger("!!!!!!!!!!!");
          System.out.println("!!!!!!!!!!");
          ResponseBuilder response = Response.ok((Object) file);  
          response.header("Content-Disposition","attachment; filename=\"sample.txt\"");  
          return response.build();  
  
      }  
  
      // This method is called if TEXT_PLAIN is request
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String sayPlainTextHello() {
      return "Hello Jersey";
    }
  
    // This method is called if XML is request
    @GET
    @Produces(MediaType.TEXT_XML)
    public String sayXMLHello() {
      return "&lt;?xml version=\"1.0\"?&gt;" + "&lt;hello&gt; Hello Jersey" + "&lt;/hello&gt;";
    }
  
    // This method is called if HTML is request
    @GET
    @Produces(MediaType.TEXT_HTML)
    public String sayHtmlHello() {
      return "&lt;html&gt; " + "&lt;title&gt;" + "Hello Jersey" + "&lt;/title&gt;"
          + "&lt;body&gt;&lt;h1&gt;" + "Hello Jersey" + "&lt;/body&gt;&lt;/h1&gt;" + "&lt;/html&gt; ";
    }
  
  } 
  </code></pre>
  
  <p>May i know what should go into maven pom.xml dependencies? i googled and add the above dependencies and still getting the same error. Am i missing any dependencies here?</p>