This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm just (after much postponing) got into using packages. I can get them to work just fine, unless I try to tinker the default directory structure.
What I got to work is just typing down "javac -d . foo.java", but not anything like "javac -d ../../foo/foobar foo.java". That is not to say it wouldn't compile, but nothing in said package is in the other classes' scope.
Perhaps my understanding of scopes is lacking, then.
My source files are located in "src\practice\dice\console", and I want them to compile to "dir\practice\dice\console".
All of the files are in a package called "practice.dice.console".
When I compile any independent class (namely, an interface that doesn't implement or extends anything), it compiles normally, and without problems.
However, when I try to compile a class that implements said interface, it claims it "cannot find symbol".
Again, this does not happen when I compile them to where I keep my source files, nor does it happen when I compile it using "javac -d . foo.java".
What happens is that Java looks for the source file you want to compile, *exactly* where you tell it. If you say javac Foo.java, it will look for Foo.java in the current directory. Files referenced from Foo.java are a different story though. All referenced files will be looked for on the classpath. By default, the classpath is the current working directory. If you have the CLASSPATH variable set in your environment variables, it will look for referenced files there. If you compile with the -classpath switch, it will look for referenced files there, overriding the CLASSPATH variable.
When I compile using the command prompt, I always go to my project folder containing my src folder, and I use the following command: "javac -classpath src -d bin src\com\example\MyClass.java". This will find MyClass.java in the src/com/example folder, and then find referenced classes under src. It doesn't matter if they are .class or .java files. Then all classes that need to be compiled will go in the bin folder, under the proper package structure.