0

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.

devoured elysium
  • 101,373
  • 131
  • 340
  • 557
  • what's your directory structure look like? If `some_file.java` is in the `some_class_path` folder, you need to be there to compile it, unless you are using a package name. – Kane Dec 08 '11 at 18:58
  • 1
    Nice abstracted compact rewriting of the problem, but in this case the actual command line matters. A cd should not be needed and a package path to the source seems missing. Compiling multiple sources probably could make use of -d directory option. – Joop Eggen Dec 08 '11 at 19:03
  • Didn't know of the -d directive. It will come in handy! – devoured elysium Dec 08 '11 at 19:06

4 Answers4

4

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
3

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

korifey
  • 3,379
  • 17
  • 17
0

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)

Tudor
  • 61,523
  • 12
  • 102
  • 142
-1

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.

Dave
  • 5,133
  • 21
  • 27