title: NoClassDefFoundError while executing main class using java -classpath command
body: <p>I have a Maven project and within that I have a <code>Main.java</code> class that contains the <code>main()</code> method that I would like to execute from Windows command prompt.  I am using the following command to execute it but it fails with an error message (show below). This program works fine from IDE.</p>
  
  <p>Similar question at stackoverflow <a href="https://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java">Why am I getting a NoClassDefFoundError in Java?</a> has been listed but does not provide a solution. It only explain the problem in a detailed manner.</p>
  
  <p>Please guide.</p>
  
  <p><strong>Command to execute main class:</strong></p>
  
  <pre><code>java -classpath target\jobchain-dataloader.jar com.ebayenterprise.ecp.jobs.Main
  </code></pre>
  
  <p><strong>Error Log:</strong></p>
  
  <pre><code>C:\office-data\v11-Projects\jobchain-dataloader&gt;java -classpath target\jobchain-dataloader.jar com.ebayenterprise.ecp.jobs.Main
  Error: A JNI error has occurred, please check your installation and try again
  Exception in thread "main" java.lang.NoClassDefFoundError: org/quartz/ScheduleBuilder
          at java.lang.Class.getDeclaredMethods0(Native Method)
          at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
          at java.lang.Class.privateGetMethodRecursive(Unknown Source)
          at java.lang.Class.getMethod0(Unknown Source)
          at java.lang.Class.getMethod(Unknown Source)
          at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
          at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
  Caused by: java.lang.ClassNotFoundException: org.quartz.ScheduleBuilder
          at java.net.URLClassLoader.findClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          ... 7 more
  </code></pre>
  
  <p><strong>Main.java</strong></p>
  
  <pre><code>package com.ebayenterprise.ecp.jobs;   
  public class Main {
  
      private static final Logger LOG = Logger.getLogger(Main.class);
  
      public static void main(String[] args) throws SchedulerException {
          LOG.debug("Scheduler started sucessfully.....");
  
          //get scheduler instance
          Scheduler scheduler = new StdSchedulerFactory().getScheduler();
          scheduler.start();
  
          //get scheduling time details
          Properties props = loadProperties("scheduler.properties");
          int mins = Integer.parseInt(props.getProperty("mins"));
  
          //kick off job
          scheduler.scheduleJob(getJobDetail(RecurringDataLoader.class), getJobTrigger(mins));
      }
  
      public static JobDetail getJobDetail(Class z) {
          return JobBuilder.newJob(z).withIdentity(RECURRING_DATA_LOADER_JOB, DATA_LOADER_JOB_GRP).build();
      }
  
      //create a simple trigger
      public static Trigger getJobTrigger(int mins) {
          Trigger trigger = TriggerBuilder.newTrigger()
                  .withIdentity(RECURRING_DATA_LOADER_TRIGGER, DATA_LOADER_TRIGGER_GRP)
                  .startNow()
                  .withSchedule(simpleSchedule()
                          .withIntervalInMinutes(mins)
                          .repeatForever())
                  .build();
          return trigger;
      }
  
  }
  </code></pre>
  
  <p><strong>pom.xml</strong> </p>
  
  <pre><code>   &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.oracle&lt;/groupId&gt;
              &lt;artifactId&gt;ojdbc7&lt;/artifactId&gt;
              &lt;version&gt;7.0&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
              &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
              &lt;version&gt;9.2-1004-jdbc41&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
              &lt;artifactId&gt;mongo-java-driver&lt;/artifactId&gt;
              &lt;version&gt;3.1.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.quartz-scheduler&lt;/groupId&gt;
              &lt;artifactId&gt;quartz&lt;/artifactId&gt;
              &lt;version&gt;2.2.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-mapper-asl&lt;/artifactId&gt;
              &lt;version&gt;1.9.13&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  </code></pre>