3

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!

1
  • Change your ./colorCalculator to just .. Commented Aug 9, 2015 at 17:53

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

8 Comments

Hmm, I have tried these commands (modified to my classes), but they still don't work. 1. I added the quotation marks around the class paths. 2. I specified the jar itself, but am still getting the same original error message.
@newbie: You shouldn't need the quotes - that's why I removed them. The important change was to use just . rather than ./colorModel. What operating system are you using thoguh? If it's Unix you should use : instead of ; as the path separator.
I'm using OS X Yosemite
@newbie: Well that's the other problem then. Will edit my answer.
Oh, sorry. Should have put that in my original post!
|
0

Classpath includes the root of your package hierarchy. So since you name your package colorCalculator, the root of that path is not './colorCalculator', but is actually just '.'.

So try -cp "../../;."

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.