title: Java class file failed to load testng class when run through command line
body: <p>I have this piece of code, which invokes <code>testNG</code> with an XML file from the main method.  I am trying to invoke this class file from command line via the following:</p>
  
  <pre><code>java -cp My_Automation.jar com.mycomp.test.sanity.InvokeTestNGTest
  </code></pre>
  
  <p>However, this fails with the following message:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/ITestListener
  </code></pre>
  
  <p>I have tried running this through Eclipse, which works perfectly fine, but it fails when invoked from the command line interface.  All testing JARs are placed in the classpath.  I don't understand the discrepancy.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>package com.mycomp.test.sanity;
  
  import java.util.ArrayList;
  import java.util.List;
  import org.testng.TestNG;
  import org.testng.TestListenerAdapter;
  
  
  public class InvokeTestNGTest {
      public static void main(String[] args) {
  
  
          List&lt;String&gt; xmlFileList = new ArrayList();
          xmlFileList.add("ILIO_testNG.xml");
          TestListenerAdapter tla = new TestListenerAdapter();
          TestNG testng = new TestNG();
  
          testng.setTestSuites(xmlFileList);
          testng.addListener(tla);
          testng.run();
  
          }
  
  }
  </code></pre>