Ben
Ben

Reputation: 337

javac file with dependency

Sorry to ask a quite common question but I can't find a working answer. I just want to compile using javac several source files organized like this:

For example, if I run

javac FullBinaryTree/Node.java

it works OK the class file is produced.

But if I run

javac FullBinaryTree/Tree.java

it will fail, reporting every Node appearance with an unknown symbol error.

As you can see the 2 files are in the same package so I'm not using any import and they are sharing the same 1st line namely

package AdaptiveHuffmanCoding.FullBinaryTree;

I guess I have to tell the compiler where to find this Node but I'm actually struggling with it. If someone could explain.

Thanks

Upvotes: 1

Views: 912

Answers (1)

davidxxx
davidxxx

Reputation: 131546

As you can see the 2 files are in the same package...

To make classes of the same package accessible by the compiler, don't execute javac directly from this package but do it from the upper lever.

To compile the Tree class :

javac AdaptiveHuffmanCoding/FullBinaryTree/Tree.java

To compile all classes of this package :

javac AdaptiveHuffmanCoding/FullBinaryTree/*.java

Note that to be compliant with Java naming conventions : packages should not contain any uppercase characters.

Upvotes: 1

Related Questions