title: Cucumber-JVM - Java 8 - Step definitions not found
body: <p>I try to add Cucumber to test my Java project, I wrote a feature file:</p>
  
  <pre><code>Feature: I visit the website
  
      Scenario: I read the home page
          Given I am on the "home" page
  </code></pre>
  
  <p>I wrote a class to run the cukes</p>
  
  <pre class="lang-java prettyprint-override"><code>import cucumber.api.CucumberOptions;
  
  /**
   *  See https://cucumber.io/docs/reference/jvm#junit-runner
   */
  @RunWith(Cucumber.class)
  @CucumberOptions(glue = {"classpath:stepdefinitions"},features = {"src/test/features"})
  public class RunCukesTest {
  }
  </code></pre>
  
  <p>And the step definition: (I've the feeling that I'm missing annotations here)</p>
  
  <pre class="lang-java prettyprint-override"><code>package com.myproject.test.stepdefinitions;
  
  import cucumber.api.PendingException;
  import cucumber.api.java8.En;
  
  public class WebSteps implements En {
  
      public WebSteps() {
          Given("^I am on the \"([^\"]*)\" page$", (String page) -&gt; {
              System.out.println(page);
          });
      }
  }
  </code></pre>
  
  <p>So whatever I put in <code>glue = {}</code>, the step is not found. With <code>glue = {"classpath:stepdefinitions"}</code> or <code>glue = {"stepdefinitions"}</code> the test is green and I have the "You can implement missing steps with the snippets below" message (the step is not found). If I put the full package path, either <code>glue = {"com.myproject.test.stepdefinitions"}</code> or <code>glue = {"classpath:com.myproject.test.stepdefinitions"}</code></p>
  
  <p>I have a stack trace: </p>
  
  <pre><code>java.lang.NoClassDefFoundError: org/springframework/test/context/ContextHierarchy
      at cucumber.runtime.java.spring.SpringFactory.annotatedWithSupportedSpringRootTestAnnotations(SpringFactory.java:198)
      at cucumber.runtime.java.spring.SpringFactory.dependsOnSpringContext(SpringFactory.java:187)
      at cucumber.runtime.java.spring.SpringFactory.addClass(SpringFactory.java:61)
      at cucumber.runtime.java.JavaBackend.loadGlue(JavaBackend.java:96)
      at cucumber.runtime.Runtime.&lt;init&gt;(Runtime.java:91)
      at cucumber.runtime.Runtime.&lt;init&gt;(Runtime.java:69)
      at cucumber.runtime.Runtime.&lt;init&gt;(Runtime.java:65)
      at cucumber.api.junit.Cucumber.createRuntime(Cucumber.java:78)
      at cucumber.api.junit.Cucumber.&lt;init&gt;(Cucumber.java:58)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
      at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
      at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
      at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
      at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
      at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
      at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  Caused by: java.lang.ClassNotFoundException: org.springframework.test.context.ContextHierarchy
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 26 more
  </code></pre>
  
  <p>Here is what I added in my <code>pom.xml</code>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;!-- Tests with cucumber --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;info.cukes&lt;/groupId&gt;
          &lt;artifactId&gt;cucumber-java8&lt;/artifactId&gt;
          &lt;version&gt;1.2.3&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;!-- Dependency Injection with Spring https://cucumber.io/docs/reference/java-di#spring --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;info.cukes&lt;/groupId&gt;
          &lt;artifactId&gt;cucumber-spring&lt;/artifactId&gt;
          &lt;version&gt;1.2.3&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;!-- JUnit Runner : https://cucumber.io/docs/reference/jvm#running --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;info.cukes&lt;/groupId&gt;
          &lt;artifactId&gt;cucumber-junit&lt;/artifactId&gt;
          &lt;version&gt;1.2.3&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;4.12&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>My project uses Spring 4.</p>