質問

Trying to understand command line compiling but having issues working with classpath, "javac: file not found: Hello.java"

  • directory structure: Users/thered/Desktop/src
  • Hello.java has default package.

These WORK from src directory:

thered-MacBook-Pro:src thered$ javac Hello.java
thered-MacBook-Pro:src thered$ javac -cp . Hello.java
thered-MacBook-Pro:src thered$ javac -cp ../src Hello.java

These FAIL from Desktop directory:

thered-MacBook-Pro:Desktop thered$ javac -cp /src Hello.java
thered-MacBook-Pro:Desktop thered$ javac -cp ./src Hello.java
thered-MacBook-Pro:Desktop thered$ javac -cp /Users/thered/Desktop/src Hello.java
役に立ちましたか?

解決

Classpath has nothing to do with where your source files are located, it points to where necessary already compiled class files and jar files are located.

If you want to be in the Desktop dir and compile src/Hello.java, just do;

javac -cp ./src src/Hello.java

or plain

javac src/Hello.java
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top