简体   繁体   中英

Trouble when trying to compile a .java file through javac

When trying to run the following command to compile some_file.java in Windows

javac -classpath "some_class_path" "some_file.java"

it fails, telling me I didn't pass it any source files.

If instead I make

cd "some_class_path"
javac -classpath "some_class_path" "some_file.java"

it works fine. Why? This bothers me as I want to compile a set of .java files from my program through javac .

It would help if you could be more concrete about your description, but it looks like you're expecting the classpath to be used to look for the files you specify on the command-line as well. It doesn't work that way - the source files you specify must be the exact paths to those files.

Try to use full path to java source file. Anyway, could you provide exact commands and exceptions?

This is not the usage of the classpath. The classpath option specifies where to find the dependencies, not the source files. Just compile using:

javac "path\file"

(windows version)

I don't think I see any obvious reason why that wouldn't work but then work if you're in that directory. Maybe quotes don't work the way I think they do in Windows. Either way, I suggest that you look at Ant , as it is the industry standard way to compile a set of java files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM