title: How can I compile classes in packages, to execute them later with "java Program" (without the package name)?
body: <p>I have a quick question regarding javac and packages in Java.</p>
  
  <p>I have a simple program (we'll call it Program.java) which is currently in the following directory:</p>
  
  <ul>
  <li>myRepository/myProgram</li>
  </ul>
  
  <p>In Program.java and other .java files in the myRepository/myProgram directory, I have declared <code>package myProgram.*</code> and also included <code>import myProgram.*;</code>.</p>
  
  <p>So when I type <code>javac myProgram/Program.java</code>, it compiles fine and it runs fine if I type <code>java myProgram/Program</code>.</p>
  
  <p>However, I'm trying to get the .class files to be produced in the <code>myRepository</code> directory, not <code>myRepository/myProgram</code>, which is where the source files are. I tried <code>javac myProgram/Program.java -d ..</code> which produces the .class files in myRepository directory, but when I try "java Program", it gives me the following error:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.NoClassDefFoundError: Program (wrong name: myProgram/Program).</p>
  </blockquote>
  
  <p>Is there any way way I could get .class files to show up in the main directory (myRepository) instead of where the source codes are (myRepository/myProgram) and be able to execute <code>java Program</code> while inside myRepository?</p>