title: Running a Java program from the command line that depends on a jar file?
body: <p>I have a simple Java file Q.java that depends on an external library file X.jar. Both Q.java and X.jar are in the same directory. I can compile Q.java from the command line by doing: "javac -cp X.jar Q.java". This generates a Q.class file. How do I run this now? I tried all these:</p>
  
  <p>1) java Q
  2) java -cp X.jar Q</p>
  
  <p>I keep getting a 
  Exception in thread "main" java.lang.NoClassDefFoundError: Q
  Caused by: java.lang.ClassNotFoundException: Q</p>
  
  <p>So how do I run this from the command line now that I have the class file?</p>