Herland Cid
Herland Cid

Reputation: 574

Javac issue, classpath not finding file inside folder, but it does outside folder

I am trying to compile a file with javac. It turns out that I can compile it in the current directory, using "." as follows.

This works:

  javac -cp "." Hello.java

But when I leave it inside a folder, it's not compiling. Example:

  javac -cp ".:/folder/" Hello.java

I've tried different combinations for the second block, but none of them has worked.

Any suggestions?

Upvotes: 0

Views: 123

Answers (2)

shazin
shazin

Reputation: 21923

You need to specify the location.

javac -cp ".:/folder/" /folder/Hello.java

Upvotes: 1

Anders R. Bystrup
Anders R. Bystrup

Reputation: 16080

The -cp option designates the classpath, not the source code location! That is, the Java compiler will look for class files there, but you'll still need to tell the compiler exactly where your source files are, eg.:

javac folder/Hello.java

if your Hello.java is in ./folder. If your Hello class depends on other classes, these should be present on the classpath:

javac -cp .:mylib:otherlibs folder/Hello.java

Cheers,

Upvotes: 3

Related Questions