I can successsfully compile any java classes using this sample code:
static String testFileName = "OOJavaBootcampTest";
System.out.println("Compiling student test source file");
String compileCommand = "cmd /c javac -d \"" + "C:\\submissions\\SOFT222\\Assessment1\\10403435\\Submission20\\OO Java Bootcamp - Java and NetBeans\\build\\test\\classes"
+ "\" -cp \"" + "C:\\submissions\\SOFT222\\Assessment1\\10403435\\Submission20\\OO Java Bootcamp - Java and NetBeans\\build\\test\\classes\\oojavabootcamp\"" + " "
+ "\" \"" + "C:\\submissions\\SOFT222\\Assessment1\\10403435\\Submission20\\OO Java Bootcamp - Java and NetBeans\\test\\oojavabootcamp" + "/"
+ testFileName + ".java\" >> \"" + ""
+ "C:\\Users\\aookpidi\\Desktop\\compilerOutput.txt" + "\" 2>&1";
System.out.println("Compile student source command: "
+ compileCommand);
try {
Runtime.getRuntime().exec(compileCommand).
waitFor(5000, TimeUnit.MILLISECONDS);
} catch (IOException | InterruptedException ex) {
}
This works fine but compiling the Junit test class with this same code but jUnit classpath added:
final static String jUnitFileName = "junit-4.11.jar";
...
String compileCommand = "cmd /c javac -d \"" + "C:\\submissions\\SOFT222\\Assessment1\\10403435\\Submission20\\OO Java Bootcamp - Java and NetBeans\\build\\test\\classes"
+ "\" -cp \"" + "C:\\submissions\\SOFT222\\Assessment1\\10403435\\Submission20\\OO Java Bootcamp - Java and NetBeans\\build\\test\\classes\\oojavabootcamp\"" + " "
+ "\"C:\\submissions\\SOFT222\\" + jUnitFileName
+ "\" \"" + "C:\\submissions\\SOFT222\\Assessment1\\10403435\\Submission20\\OO Java Bootcamp - Java and NetBeans\\test\\oojavabootcamp" + "/"
+ testFileName + ".java\" >> \"" + ""
+ "C:\\Users\\aookpidi\\Desktop\\compilerOutput.txt" + "\" 2>&1";
The test.java file doesnt seem to copy to the specified directory in -d. This is error in the compilerOutput file:
javac: invalid flag: C:\submissions\SOFT222\junit-4.11.jar
Usage: javac <options> <source files>
use -help for a list of possible options
Junit is definitely in the specified location.