I am trying to run the following
javac -Xlint:unchecked -classpath C:/Users/a b/workspace/ @C:/Users/a b/workspace/files_to_compile
but I'm getting a
javac: invalid flag C:/users/a
I've also tried to surround both paths with double quotes but it doesn't seem to help a bit:
javac -Xlint:unchecked -classpath "C:/Users/a b/workspace/" @"C:/Users/a b/workspace/files_to_compile"
What am I doing wrong? This same code worked correctly in other computers (probably because they didn't have any white space in their paths..).
Thanks
I've finally come up with the solution to the issue, and I guess no one here could have guessed it.
The cue to the answer lies with the fact that the contents of the files list (signaled as @ in the args) generally will have each one of its strings with the initial substring equal to what one passes as both the class path and the @ file.
so..
The trouble was never the command line parameters, as suggested, but with the contents of the @ file.
Each line of the file must be put in its own line, surrounded by quotes, and having into consideration that if you're in windows, you have to put the file names in the form of
C:\\a\\b\\c.txt
!!!Your second try is right
But to be complete, you have to escape the spaces into the text file "files_to_compile" by using:
or
I suggest the second but I'm not sure.
Its taking only the 1st part of the Source String remove the space between
a b
from the path and it should work fineC:/Users/a_b/workspace/" @"C:/Users/a_b/workspace/files_to_compile"
. Never you should have spaces in the path else the latter part will be ignored by the compiler or else you can put a '\' betweena\ b
Bit of a hack, but if you're on Windows 7 you can get around this using the
mklink
utility to create another folder pointing to the same place, but without spaces.Edit: perhaps a better solution:
You need to escape spaces.
Put a
\
in front of each space and try that.I have to admit this was more difficult than I had imagined. After some trial and error I came up with the following:
C:\lol>"C:\Program Files\Java\jdk1.7.0_07\bin\javac" -cp "c:\lol\a b;c:\lol\foo bar" Lol.java
where the folder structure is like:
I made an archive with the folders and the java files, which you can grab at: http://www.pvv.ntnu.no/~rakhmato/tmp/lol.tar
You should ignore the @ option because it is enough to give the compiler one file and a proper class path, it can figure out where everything is on its own. Just give the compiler your Main.java and it will figure out what that file depends on.
I would also recommend you to write a .bat script of sorts to make things simpler. Nothing fancy, something like this:
compile.bat:
"C:\Program Files\Java\jdk1.7.0_07\bin\javac" -classpath "c:\lol\a b;c:\lol\foo bar" Main.java
..put that in your project folder and run compile.bat from CMD