Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It works if you compile into a separate target directory. E.g,</p> <pre><code>mkdir target javac -d target/ src/*.java javac -classpath target/ test/*.java </code></pre> <p>When you do <code>javac src/*.java</code>, it will create the <code>.class</code> file in the <code>src</code> directory itself. By default, any classes you reference are assumed to be in the same package. So even if you add <code>src/</code> to the classpath, it looks for <code>src/ProjectName/SourceClass.class</code>, which it does not find. When you pass the <code>-d target/</code> option, it creates the proper package hierarchy, so and finds the class.</p> <p>Relevant documentation from the <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html" rel="nofollow">javac official doc</a>:</p> <blockquote> <p>You should arrange source files in a directory tree that reflects their package tree. For example, if you keep all your source files in C:\workspace, the source code for com.mysoft.mypack.MyClass should be in C:\workspace\com\mysoft\mypack\MyClass.java.</p> <p>By default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with -d (see Options, below).</p> <p>...</p> <p>...</p> <p><strong>-d</strong> <em>directory</em> Set the destination directory for class files. The directory must already exist; javac will not create it. If a class is part of a package, javac puts the class file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify -d C:\myclasses and the class is called com.mypackage.MyClass, then the class file is called C:\myclasses\com\mypackage\MyClass.class. If -d is not specified, javac puts each class files in the same directory as the source file from which it was generated.</p> <p>Note: The directory specified by -d is not automatically added to your user class path.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload