问题描述
我有一个Ski.java文件。我把它手动放在一个名为package1的文件夹中。
然后我在package1之外创建了另一个文件夹,但在同一层次结构中命名为package1。
package1& package2在D:\ src目录中。
$ 2 $ b在package2中,我制作了Mainclass.java&尝试导入package1并在其中使用Ski类。
然后在命令提示符下,我已经在自己的文件夹中编译了Ski.java,使用以下命令
D:\ src \ package1> javac Ski.java
然后我试图在其文件夹中编译MainClass,如下所示:
D:\ src \ package2> javac MainClass.java
但它没有编译。
编译错误是package1不存在。
请给我一个解决方案。
I have a Ski.java file. I have put it manually in a folder named package1.
Then I made another folder outside the package1 but in the same hierarchy named package1.
Both package1 & package2 are in D:\src directory.
in package2, I made Mainclass.java & trying to import package1 and use Ski class in it.
then in command prompt, I have compiled Ski.java in its own folder, using following command
D:\src\package1>javac Ski.java
then I am trying to compile MainClass in its folder, like this:
D:\src\package2>javac MainClass.java
But it is not compiled.
Compile error is that package1 doesnot exist.
please give me a solution.
推荐答案
D:\src\package2>javac -classpath D:\src\package1 MainClass.java
D:\src\package2\javac -classpath ..\ MainClass.java
添加一个类路径选项,你可以告诉编译器在哪里找到jar和类文件。
希望这会有所帮助,
Fredrik
By adding a classpath option you can tell the compiler where to find jars and class files.
Hope this helps,
Fredrik
这篇关于紧急:Java中的打包问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!