Answer the question
In order to leave comments, you need to log in
Why is the CLASSPATH variable ignored after creating a package in a Java program?
The CLASSPATH environment variable contains paths to several .jar libraries (.;D:\lib1.jar; D:\lib2.jar). If you do not use packages (more precisely, use the default package) in programs, access to classes from these libraries is carried out without problems. But if you use a package, javac throws an error saying it doesn't know such classes.
That is, for example, this compiles fine:
javac C1.java
public class C1 {
public void method() {
ClassFromLib1.method();
}
}
javac C1.java
package P1;
public class C1 {
public void method() {
ClassFromLib1.method();
}
}
error: cannot find symbol
ClassFromLib1.method();
symbol: variable ClassFromLib1
Answer the question
In order to leave comments, you need to log in
Problem solved. It turns out that the classes from the libraries that I used were in the default package, and in Java you cannot call classes from the default package in any named package.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question