Reputation: 4560
I have a java project that has two packages 'a' and 'b'. A class in 'a' depends on a class in 'b', I compiled the class in 'b' (using javac classname.java) but when I try to compile my class in 'a' the package 'b' isn't recognized. I explicitly import it using a line like this:
import b.*;
I read online that the full package name is to be given, and that's what I think I'm doing in my import statement given the fact that both my packages are directly under the src folder.
Would anyone have an idea on how to fix this problem ? Thanks in advance
Upvotes: 2
Views: 101
Reputation: 1348
The below would have been the error you would have got .
C:\Users\id831496\Desktop\New folder\a>javac ClassA.java
ClassA.java:3: package b does not exist
import b.*;
^
ClassA.java:5: cannot find symbol
symbol : class ClassB
location: class a.ClassA
ClassB classB = null;
^
2 errors
What needs to be done is add an classpath argument like below
C:\Users\id831496\Desktop\New folder\a>javac -cp ..\b\* ClassA.java
C:\Users\id831496\Desktop\New folder\a>
Upvotes: 1
Reputation: 5657
What you may be doing is compiling from the package folder itself. If so, then you will need to exit directory so that you are instead inside the source directory, and then compile with the following command:
javac a/ClassInA.java
Where "ClassInA" is the name of the class in the "a" package.
Upvotes: 2