Javac: compiling a .java file that uses other classes in it

HI I have 3 java files

a.java  
b.java  
c.java  

I managed to create .class files for a and b using

javac example/a.java  
javac example/b.java  

but when I do the same for c.java, I get the error error: cannot find character b and c

Any suggestions on how I can solve this problem?

All java files are in one folder

+5
source share
2 answers

You have to have classes aand bin your classpath when you try to compile the class c. This allows the compiler to verify that they exist, to find out what methods they have, etc.

javacquite sensitive to package names and classes. The simplest thing is to collect all three at the same time javac example/a.java example/b.java example/c.java.

( src), :

javac -cp src src/example/c.java

, , , , example. - javac example , a.class b.class.

+13

, example/ javac.

javac -cp example c.java

cd . c.java .

+2

All Articles