开发者

Java will not compile properly from the command line "cannot find my source files"

开发者 https://www.devze.com 2023-01-19 05:45 出处:网络
I am trying to compile my source code from the Windows 7 command prompt. I have added the directory in which my *.java file is located to the classpath. Yet, I still get this error:

I am trying to compile my source code from the Windows 7 command prompt. I have added the directory in which my *.java file is located to the classpath. Yet, I still get this error:

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

I'm very confused as to why this happens because if I navigate to the folder where this file is located, it will compile. However, this is not a satisfactory solution since I intend on compiling JUnit tests directly from the command line as well.

Other solutions I have attempted:

C:\Users\Alex>javac -classpath "C开发者_JS百科:\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

I do not think this has ANYTHING to do with typos.

Why can't I compile my project like this?


The CLASSPATH variable is not used by javac to find where your source code lives. Use the -sourcepath arg to javac instead.

Save yourself a lot of time and manual typing and use a build tool like Apache Ant or Maven.


You don't want to use classpath, that tells the compiler where to find externally referenced .class files used by your file. You want to use -sourcepath which tells javac where your .java files may be hiding.

0

精彩评论

暂无评论...
验证码 换一张
取 消