I'm not sure why I can't process this right now, but I have four packages in one source folder:
./src/common
./src/server
./src/client
./src/unittest
Common uses no files from any of the others, but server and client use files from the common package. In each of the files in those packages I have import common.*
. But when I run the compiler with javac ./src/server/*.java
it can't find the common
package.
The only info I can seem to find is for tree structured package hierarchies, but how do I reference something at the same folder height as me? Do I need to nest common inside both server and client? That seems likely to generate a lot of redundant code.
I'm sure this is probably a question someone has asked before, so I apologize, but I cannot find it anywhere.
If you want it to find those files automatically without having to specify them, you'll need to be in the package root, so run this from within src
:
javac server/*.java
That would then work.
However, personally I would always specify all the code you want to build, rather than letting javac
pick up extra bits. If you want to build the common
code first, I'd do so and then add a classpath entry so that javac
will pick up the compiled classes rather than the source code.
(Alternatively, I'd spend most of the time in an IDE where it's largely automatic, and then use a fuller build system such as Ant to do the actual building.)
See more on this question at Stackoverflow