title: Error when deploying a REST service via Jersey on a Virtual Machine
body: <p>I have a simple web service exposing Java resources through REST using Jersey2 and Jetty. It works fine on my laptop's localhost. However, when I deploy the same code onto a virtual machine on my company's network, I get an error. Without Jersey, Jetty runs successfully and the welcome page displays fine on the virtual machine.</p>
  
  <p>I have searched for similar issues and found <a href="https://stackoverflow.com/questions/22265649/jersey2-sample-rest-service-failing"><strong>this promising one</strong></a>, however what worked for <em>PrasanthNath</em> doesn't seem to apply to my case. I have tried with version 2.6 of the libraries suggested on that link, too but it didn't make a difference.</p>
  
  <p>I'd highly appreciate your thoughts. Thank you in advance!</p>
  
  <p>Here's the error I get:</p>
  
  <pre><code>$ gradle jettyRunWar
  :compileJava UP-TO-DATE
  :processResources UP-TO-DATE
  :classes UP-TO-DATE
  :war UP-TO-DATE
  :jettyRunWar
  failed Jersey REST Service: java.lang.NoSuchFieldError: INCLUDE_ALL
  failed org.gradle.api.plugins.jetty.internal.JettyPluginWebAppContext@248d3e1b{/dgp_ky_140310,/home/unix    /kyuksel/dgp_ky_140310/build/libs/dgp_ky_140310-0.1.war}: java.lang.NoSuchFieldError:     INCLUDE_ALL
  failed ContextHandlerCollection@7915b3e: java.lang.NoSuchFieldError: INCLUDE_ALL
  failed HandlerCollection@57fd4753: java.lang.NoSuchFieldError: INCLUDE_ALL
  
  Error starting handlers
  java.lang.NoSuchFieldError: INCLUDE_ALL
  at org.glassfish.jersey.server.ResourceConfig$State.&lt;init&gt;(ResourceConfig.java:110)
  at org.glassfish.jersey.server.ResourceConfig.&lt;init&gt;(ResourceConfig.java:351)
  at org.glassfish.jersey.servlet.WebComponent.createResourceConfig(WebComponent.java:427)
  at org.glassfish.jersey.servlet.WebComponent.&lt;init&gt;(WebComponent.java:294)
  at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)
  at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)
  at javax.servlet.GenericServlet.init(GenericServlet.java:241)
  at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
  at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
  at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
  at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
  at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1272)
  at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
  at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:489)
  at org.gradle.api.plugins.jetty.internal.JettyPluginWebAppContext.doStart(JettyPluginWebAppContext.java:112)
  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
  at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
  at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
  at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
  at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
  at org.mortbay.jetty.Server.doStart(Server.java:224)
  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
  at org.gradle.api.plugins.jetty.internal.Jetty6PluginServer.start(Jetty6PluginServer.java:111)
  at org.gradle.api.plugins.jetty.AbstractJettyRunTask.startJettyInternal(AbstractJettyRunTask.java:238)
  at org.gradle.api.plugins.jetty.AbstractJettyRunTask.startJetty(AbstractJettyRunTask.java:191)
  at org.gradle.api.plugins.jetty.AbstractJettyRunTask.start(AbstractJettyRunTask.java:162)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
  at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219)
  at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
  at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
  at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:533)
  at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:516)
  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
  at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
  at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
  at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
  at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
  at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
  at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
  at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
  at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:289)
  at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
  at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
  at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
  at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.java:33)
  at org.gradle.internal.Factories$1.create(Factories.java:22)
  at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:198)
  at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:266)
  at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:135)
  at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:95)
  at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:31)
  at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)
  at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
  at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
  at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
  at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
  at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
  at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
  at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
  at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
  at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
  at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
  at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
  at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
  at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
  at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
  at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
  at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
  at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
  at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
  at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
  at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
  at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
  at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
  at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
  at org.gradle.launcher.Main.doAction(Main.java:46)
  at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
  at org.gradle.launcher.Main.main(Main.java:37)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
  at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
  at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
  </code></pre>
  
  <p>This is the snapshot of the <strong>org.glassfish.jersey.server.ResourceConfig</strong> code where the error (<strong>line 110</strong>) is coming from:</p>
  
  <pre><code>109  public More ...State() {
  110      super(RuntimeType.SERVER, ComponentBag.INCLUDE_ALL);
  111      this.classLoader = AccessController.doPrivileged(ReflectionHelper.getContextClassLoaderPA());
  112 
  113      this.resourceFinders = Sets.newHashSet();
  114 
  115      this.resources = Sets.newHashSet();
  116      this.resourcesView = Collections.unmodifiableSet(this.resources);
  117  }
  </code></pre>
  
  <p>Here's my <strong>build.gradle</strong> with the dependencies:</p>
  
  <pre><code>version = '0.1'
  
  apply plugin: 'java'
  apply plugin: 'idea'
  apply plugin: 'checkstyle'
  apply plugin: 'jetty'
  apply plugin: 'war'
  
  checkstyle {
      configFile = new File(rootDir, "checkstyle/checkstyle.xml")
  }
  
  jar {
      manifest {
          attributes 'Main-Class': 'org.broadinstitute.genomestore.GenomeStore',
                 'Implementation-Title': 'GenomeStore',
                 'Implementation-Version': version
  }
      from { 
              configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } 
      }
  }
  
  repositories {
      mavenCentral()
  
      maven {
          url "https://google-api-client-libraries.appspot.com/mavenrepo"
      }
  }
  
  dependencies {
      compile 'ch.qos.logback:logback-classic:1.0.13'
      compile 'com.google.api-client:google-api-client:1.17.0-rc'
      compile 'com.google.apis:google-api-services-storage:v1beta2-rev36-1.17.0-rc'
      compile 'com.google.http-client:google-http-client-jackson2:1.17.0-rc'
      compile 'com.google.apis:google-api-services-bigquery:v2-rev129-1.17.0-rc'
      compile 'javax.json:javax.json-api:1.0'
      compile 'javax.ws.rs:javax.ws.rs-api:2.0'
      compile 'org.glassfish.jersey:jax-rs-ri:2.0-rc1'
      compile 'org.glassfish.jersey.core:jersey-server:2.4'
      compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.4'
      compile 'org.glassfish.jersey.media:jersey-media-json-processing:2.7'
      compile 'org.slf4j:slf4j-api:1.7.5'
      providedCompile 'javax.servlet:servlet-api:2.5'
      runtime 'javax.servlet:jstl:1.1.2'
  }
  
  task(runGenomeStore, dependsOn: 'classes', type: JavaExec) {
      main = 'org.broadinstitute.genomestore.GenomeStore'
  
      classpath = sourceSets.main.runtimeClasspath
  }
  
  defaultTasks 'build'
  </code></pre>
  
  <p>Here's my <strong>web.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
       http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;ResultStoreServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.broadinstitute.genomestore.rest.ResultStoreServlet&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;ResultStoreServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/Hello&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;display-name&gt;dgp_ky_140310&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;org.broadinstitute.genomestore.rest&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;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  </code></pre>
  
  <p></p>
  
  <p>And finally here's my sample class:</p>
  
  <pre><code>@Path("/server/")
  public class Server {
  
      @GET
      @Produces("application/json")
      public JsonObject getJson() {
          JsonObject model = Json.createObjectBuilder()
              .add("gene_info", Json.createObjectBuilder()
                  .add("DESCRIPTION", "The protein encoded by this gene ...")
                  .add("NAME", "XXX")
                  .add("SYMBOL", "YYY")
                  .add("VARIANT_SUMMARY", Json.createObjectBuilder()
                      .add("NEAR_GENE_NOMINAL", "99")
                      .add("OTHER_TRAIT_GENOMEWIDE", "99")                   
                      .add("TOTAL_VARIANTS", "289")))
              .add("is_error", false)
              .build();
  
          return model;
      }
  }
  </code></pre>