title: Cucumber - java.lang.NoClassDefFoundError
body: <p>I'm learning cucmber and I'm facing the following errors while running the test:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: cucumber/io/ResourceLoader
  
      at java.lang.Class.getDeclaredConstructors0(Native Method)
      at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
      at java.lang.Class.getConstructor0(Class.java:3075)
      at java.lang.Class.getConstructor(Class.java:1825)
      at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
      at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
      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:33)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
      at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
  Caused by: java.lang.ClassNotFoundException: cucumber.io.ResourceLoader
      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)
      ... 19 more
  </code></pre>
  
  <p>Files:</p>
  
  <ol>
  <li>src/test/java/Annotation/runTest.java</li>
  <li>src/test/java/Annotation/annotation.java</li>
  <li>src/test/java/Annotation/annotation.feature</li>
  <li>pom.xml</li>
  </ol>
  
  <p><strong>src/test/java/Annotation/runTest.java</strong></p>
  
  <pre><code>package Annotation;
  
  import org.junit.runner.RunWith;
  import cucumber.junit.Cucumber;
  
  @RunWith(Cucumber.class)
  @Cucumber.Options(
          format = {"pretty", "html:target/cucumber"},
          features = {"src/test/java/annotation/annotation.feature"}
  )
  
  public class runTest { }
  </code></pre>
  
  <p><strong>src/test/java/Annotation/annotation.java</strong></p>
  
  <pre><code>package Annotation;
  
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.chrome.ChromeDriver;
  
  import cucumber.annotation.en.Given;
  import cucumber.annotation.en.Then;
  import cucumber.annotation.en.When;
  
  public class annotation {
      WebDriver driver = null;
      @Given("^I am on Facebook login page$")
  
      public void goToFacebook() {
          driver = new ChromeDriver();
          driver.navigate().to("https://www.facebook.com/");
      }
  
      @When("^I enter username as \"(.*)\"$")
      public void enterUsername(String arg1) {
          driver.findElement(By.id("email")).sendKeys(arg1);
      }
  
      @When ("^I enter password as \"(.*)\"$")
      public void enterPassword(String arg1) {
          driver.findElement(By.id("pass")).sendKeys(arg1);
          driver.findElement(By.id("u_0_v")).click();
      }
  
      @Then("^Login should fail$")
      public void checkFail() {
          if(driver.getCurrentUrl().equalsIgnoreCase(
                  "https://www.facebook.com/login.php?login_attempt=1&amp;lwv=110")){
              System.out.println("Test1 Pass");
          } else {
              System.out.println("Test1 Failed");
          }
          driver.close();
      }
  
      @Then("^Relogin option should be available$")
      public void checkRelogin() {
          if(driver.getCurrentUrl().equalsIgnoreCase(
                  "https://www.facebook.com/login.php?login_attempt=1&amp;lwv=110")){
              System.out.println("Test2 Pass");
          } else {
              System.out.println("Test2 Failed");
          }
          driver.close();
      }
  }
  </code></pre>
  
  <p><strong>src/test/java/Annotation/annotation.feature</strong></p>
  
  <pre><code>Feature: annotation
  #This is how background can be used to eliminate duplicate steps
  
    Background:
    User navigates to Facebook Given
    I am on Facebook login page
  
  #Scenario with AND
    Scenario:
      When I enter username as "TOM"
      And I enter password as "JERRY"
      Then Login should fail
  
  #Scenario with BUT
    Scenario:
      When I enter username as "TOM"
      And I enter password as "JERRY"
      Then Login should fail
      But Relogin option should be available
  </code></pre>
  
  <p><strong>pom.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &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;nice.git.sample&lt;/groupId&gt;
      &lt;artifactId&gt;hello-world&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
      &lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
              &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
              &lt;version&gt;3.0.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;info.cukes&lt;/groupId&gt;
              &lt;artifactId&gt;cucumber-java&lt;/artifactId&gt;
              &lt;version&gt;1.2.5&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;info.cukes&lt;/groupId&gt;
              &lt;artifactId&gt;cucumber-core&lt;/artifactId&gt;
              &lt;version&gt;1.2.5&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&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.5&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;LATEST&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
              &lt;artifactId&gt;selenium-api&lt;/artifactId&gt;
              &lt;version&gt;2.47.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;info.cukes&lt;/groupId&gt;
              &lt;artifactId&gt;cucumber-junit&lt;/artifactId&gt;
              &lt;version&gt;1.0.2&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;info.cukes&lt;/groupId&gt;
              &lt;artifactId&gt;cucumber-java&lt;/artifactId&gt;
              &lt;version&gt;1.0.2&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;info.cukes&lt;/groupId&gt;
              &lt;artifactId&gt;cucumber-core&lt;/artifactId&gt;
              &lt;version&gt;1.1.8&lt;/version&gt;
          &lt;/dependency&gt;
  
  
  
      &lt;/dependencies&gt;
  
  &lt;/project&gt;
  </code></pre>