I'm trying to compile my Java code with this command (OS X Yosemite):
javac -cp "../../;./colorCalculator;" Application.java
but I get the following errors (among others that are dependent on this):
Application.java:4: error: package colorCalculator does not exist
import colorCalculator.Model;
^
Application.java:5: error: package colorCalculator does not exist
import colorCalculator.View;
^
Application.java:6: error: package colorCalculator does not exist
import colorCalculator.Controller;
I have added two class paths. 1. The path for a ".jar" that this application is dependent on. 2. The package that Application.java imports from.
The directory structure is as such:
├── colorcalculator
│ ├── Application.java
│ └── colorCalculator
│ ├── Controller.java
│ ├── Model.java
│ └── View.java
└── colorcalculator.zip
I run the command from the colorcalculator directory, because that's where Application.java and the colorCalculator package are. What am I doing wrong?
Lastly, the code for your reference if you would like it. It is from a professor's website though, so I'm pretty sure it's correct: code
Thanks!
The classpath is meant to include the root of the package structure for any appropriate directory. So the compiler is currently looking for ../../colorCalculator/Model.class
or ./colorCalculator/colorCalculator/Model.class
when you actually just want it to look for ./colorCalculator/Model.class
Additionally, as you're using OS X, you should use : instead of ; as the path separator.
So you should have:
javac -cp ../..:. Application.java
Note that you haven't actually added a path to a jar file at all - if you've got a jar file in ../..
you actually want
javac -cp ../../whatever.jar:. Application.java
See more on this question at Stackoverflow