【问题标题】:Java will not compile properly from the command line "cannot find my source files"Java 无法从命令行正确编译“找不到我的源文件”
【发布时间】:2010-10-11 00:13:51
【问题描述】:

我正在尝试从 Windows 7 命令提示符编译我的源代码。我已将*.java 文件所在的目录添加到类路径中。但是,我仍然收到此错误:

C:\Users\Alex>javac HelloThere.java
javac: file not found: HelloThere.java
Usage: javac <options> <source files>
use -help for a list of possible options

我很困惑为什么会发生这种情况,因为如果我导航到该文件所在的文件夹,它将编译。但是,这不是一个令人满意的解决方案,因为我也打算直接从命令行编译 JUnit 测试。

我尝试过的其他解决方案:

C:\Users\Alex>javac -classpath "C:\Users\Alex\AndroidProject\UnitTest\src" HelloThere.java
javac: file not found: HelloThere.java
Usage: javac <options> <source files>
use -help for a list of possible options

我认为这与拼写错误没有任何关系。

为什么我不能像这样编译我的项目?

【问题讨论】:

  • 您的文件和/或类名中有空格?删除它,然后重试。
  • 到底为什么,既然没有人问过,你不使用像 Eclipse 这样的 IDE 吗?
  • 如果“Hello There”程序类似于“Hello World”程序,他可能才刚刚开始 :) 但你说得很好,下一步,探索 IDE。

标签: java command-line javac


【解决方案1】:

javac 不使用 CLASSPATH 变量来查找源代码所在的位置。请改用-sourcepath arg to javac

为自己节省大量时间和手动输入,并使用像 Apache AntMaven 这样的构建工具。

【讨论】:

  • 或者通过将列表缩短为 Ant 来节省大量时间和麻烦。 :)
【解决方案2】:

您不想使用类路径,它会告诉编译器在哪里可以找到您的文件使用的外部引用的 .class 文件。您想使用 -sourcepath 告诉 javac 您的 .java 文件可能隐藏在哪里。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-26
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2011-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多