javac:编译使用其中的类的.java文件 [英] javac : Compiling a .java file which uses other classes in it
问题描述
HI我有3个java文件
a.java
b.java
c.java
我设法使用
为a和b生成.class文件
javac example / a.java
javac example / b.java
但是当我对c.java也这样做时得到错误
错误:找不到符号b和c
<任何建议,如何我可以解决这个问题?
所有Java文件都在同一个文件夹中
当你尝试编译类 c
a
和 b
/ code>。这允许编译器验证它们存在,弄清楚他们有什么方法等。
javac
对程序包名称和类路径敏感。最简单的做法是同时编译所有三个,像这样 javac example / a.java example / b.java example / c.java
。
如果你转到example的父目录(我们称之为 src
),那么你可以运行以下命令:
javac -cp src src / example / c.java
你必须这样做的原因是因为你的类的包被列为 example
。由于您的程序包名称, javac
正在其类路径中寻找示例
目录,其中希望找到 a.class
和 b.class
。
HI i have 3 java files
a.java
b.java
c.java
I managed to generate .class files for both 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 symbol b and c
Any suggestions on how i could solve this problem ?
All the java files are in the same folder
You have to have classes a
and b
in your classpath when you try to compile class c
. This allows the compiler to verify that they exist, figure out what methods they have, etc.
javac
is pretty sensitive to package names and classpaths. The easiest thing to do is to compile all three at the same time like so javac example/a.java example/b.java example/c.java
.
If you go to the parent directory of example (let's call it src
), then you can run the following:
javac -cp src src/example/c.java
The reason you have to do it this way is because your classes have their packages listed as example
. Because of your package name, javac
is looking for the example
directory in its classpath, where it expects to find a.class
and b.class
.
这篇关于javac:编译使用其中的类的.java文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!