title: Class in a package - Exception in thread "main" java.lang.NoClassDefFoundError
body: <p>I am trying to run a jar file in Hadooop (Ubuntu Linux).</p>
  <p>My file 'Project1.java' has a package defined, before the class, like this:</p>
  <pre><code>package myPackage.comp;
  public class Project1 {
  ---lines of code here---
  }
  </code></pre>
  <p>I use the following commands to try to run it:</p>
  <pre><code>$ hadoop com.sun.tools.javac.Main Project1.java
  $ jar cf proj1.jar Project1*.class
  $ hadoop jar proj1.jar Project1 input output
  </code></pre>
  <p>and I get the following error:</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: comp/proj1/Project1 (wrong name: Project1)
      at java.base/java.lang.ClassLoader.defineClass1(Native Method)
      at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
      at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
      at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:550)
      at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:458)
      at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:452)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:451)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
      at java.base/java.lang.Class.forName0(Native Method)
      at java.base/java.lang.Class.forName(Class.java:398)
      at org.apache.hadoop.util.RunJar.run(RunJar.java:316)
      at org.apache.hadoop.util.RunJar.main(RunJar.java:236)
  </code></pre>
  <p>When I look into the generated proj1.jar file, I can see a Project1.java class file in it.</p>
  <p>What am I missing here?</p>
  <p><strong>Update</strong>: If I remove the line</p>
  <pre><code>package myPackage.comp;
  </code></pre>
  <p>It works perfectly.</p>
  <p>How can I get it to work when including the class in a package?</p>