Note that there are some explanatory texts on larger screens.

plurals
  1. POjava compiling from the command line
    text
    copied!<p>I am an experienced programmer, but haven't used Java in years - mostly C# - and used an IDE in the past. I'm trying to compile some code from the command line on my Mac, but can't get my test file to find my source code. I'm assuming the problem lies somewhere in the space of packages, file structure, classpaths, and import statements - but I've put a couple hours in (including hunting on Stack Overflow) and am still stuck.</p> <p>Here's what I have:</p> <pre><code>Directory structure: ProjectName | --src | --SourceClass --test | --SourceClassTest --external | --testng-6.8.7.jar </code></pre> <p>My SourceClass looks like this:</p> <pre><code>package ProjectName; public class SourceClass&lt;T&gt;{ } </code></pre> <p>Very simple. Obviously, there will be more - but I wanted to start with making sure I had all this setup stuff correct before I actually did coding.</p> <p>My test class looks like this:</p> <pre><code>package ProjectName; import java.util.*; import org.testng.Assert; import org.testng.annotations.*; public class SourceClassTest{ @Test private void createEmptySourceClass(){ SourceClass&lt;Object&gt; sourceClass = new SourceClass&lt;Object&gt;(); Assert.assertTrue(sourceClass.isEmtpy()); } } </code></pre> <p>The sourceClass compiles with no issue with "javac src/*.java", run from the "ProjectName" directory. I want to see this fail with an error along the lines of "SourceClass doesn't have an isEmpty() method", but instead I run javac like this from the "ProjectName" directory:</p> <pre><code>javac test/*.java -classpath external/testng-6.8.7.jar </code></pre> <p>and get this exception:</p> <pre><code>test/SourceClassTest.java:12: error: cannot find symbol SourceClass&lt;Object&gt; tree = new SourceClass&lt;Object&gt;(); ^ symbol: class SourceClass location: class SourceClassTest test/SourceClassTest.java:12: error: cannot find symbol SourceClass&lt;Object&gt; sourceClass = new SourceClass&lt;Object&gt;(); ^ symbol: class SourceClass location: class SourceClassTest 2 errors </code></pre> <p>I've tried a lot of things -adding an import statement, adding a sourcepath to the javac command, compiing the sourceClass as a jar and putting it in the bin directory then adding that to the classpath, but I can't get the test to find the SourceClass symbols.</p> <p>Any idea what I am missing here?</p>
 

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