Calling the javac command from Windows XP with the source files argument containing a wildcard in quotes – e.g. javac "*.java" will result in the error:
javac: file not found:
Whereas with no quotes – e.g. javac *.java , no error is produced.
Consider a source files argument containing both a path and wildcard combined – e.g. javac C:\temp\*.java , this is perfectly fine and no error is produced.
The following however will fail –e.g. javac "C:\my documents\*.java" , due to the wildcard in quotes issue above.
Some may argue that this is perfectly reasonable, given that java does not allow spaces in package names. But what if the java files above in the “my documents” folder are top-level classes without package qualification – such as the file below:
public static void main(String args)
Consider a simple java kit that you deliver to folks with the following structure:-
If the kit above is extracted to some folder/directory without spaces, it should be pretty easy to compile from the command-line. Whereas if it were extracted to the standard Windows desktop location as shown below, more care must be taken:
C:\Documents and Settings\Administrator\Desktop\MyApplication\
One will not be able to run javac "C:\Documents and Settings\Administrator\Desktop\MyApplication\src\com\acme\myapp\*.java" . They must instead change directory to an appropriate location whereby the javac source files argument can be supplied without including quotes. For example:
cd /D "C:\Documents and Settings\Administrator\Desktop\MyApplication"
Below is a sample windows java compile batch script that I’ve created that should work with the application structure above regardless of what destination directory the kit is extracted to:-
REM Changes made to an Environment Variable after SETLOCAL has been issued are local to the batch file.
REM Issuing an ENDLOCAL command will restore the previous environment variables.
REM library files and source location
REM source base package path
REM classes directory
REM generated library destination path and file
REM classpath for compilation
REM MAIN PROGRAM
REM Verify whether required variables are set
IF "%JAVA_HOME%x"=="x" GOTO errjava
REM Preparation ...
IF EXIST "%DEST_JAR_FILE%" DEL /q "%DEST_JAR_FILE%"
IF EXIST "%PROJECT_CLASSES%" RMDIR /s /q "%PROJECT_CLASSES%"
ECHO Compiling code ...
"%JAVACMPCMD%" -target 1.6 -classpath "%CP%" -d "%PROJECT_CLASSES%" *.java utils\*.java
IF NOT "%ERR%"=="0" GOTO errcomp
ECHO Creating jar file ...
"%JARCMD%" cfM "%DEST_JAR_FILE%" -C "%PROJECT_CLASSES%/" .
IF NOT "%ERRORLEVEL%"=="0" GOTO errjar
REM Cleanup ...
RMDIR /s /q "%PROJECT_CLASSES%"
REM JAVA_HOME is not set
ECHO Set the following environment variables:
ECHO JAVA_HOME (Absolute path to jdk directory)
ECHO Compilation did not succeed.
ECHO Note: If receiving read errors, ensure folder path does not contain whitespace.
ECHO Jar creation did not succeed.