I can easily compile any Java classes using this code:
System.out.println("Compiling student source files");
Path destinationCompiledClassFile = Paths.get("/submissions/" + moduleCode + "/Assessment" + assessmentNumber + "/" + studentId + "/Submission"
+ submissionNumber + "/" + assessmentFolderName + "/" + "build/classes/");
Path classPath = Paths.get("/submissions/" + moduleCode + "/Assessment" + assessmentNumber + "/" + studentId + "/Submission"
+ submissionNumber + "/" + assessmentFolderName + "/" + "build/classes/oojavabootcamp" + "/");
Path javaFileToCompile = Paths.get("/submissions/" + moduleCode + "/Assessment" + assessmentNumber + "/" + studentId + "/Submission"
+ submissionNumber + "/" + assessmentFolderName + "/" + "src/OOJavaBootcamp");
for (String fileToCompile : filesToCompile) {
String compileCommand = "cmd /c javac -d \"" + destinationCompiledClassFile
+ "\" -cp \"" + classPath
+ "\" \"" + javaFileToCompile + "/"
+ fileToCompile + ".java\" >> \""
+ submissionPathString + "/"
+ compilerOutputFileName + "\" 2>&1";
I am trying to compile the test.class file in a simple Java application by adding JUnit JAR file in the classpath. This should add the new compiled test.class file to the specified -d directory. I have deleted the existing file in this path 'C:\submissions\SOFT222\Assessment1\10403435\Submission20\OO Java Bootcamp - Java and NetBeans\build\test\classes\oojavabootcamp' and need the new compiled file here.
static String testFileName = "OOJavaBootcampTest";
final static String jUnitFileName = "junit-4.11.jar";
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\\" + jUnitFileName
+ "\"; \"" + "C:\\submissions\\SOFT222\\Assessment1\\10403435\\Submission20\\OO Java Bootcamp - Java and NetBeans\\test\\oojavabootcamp" + "/"
+ testFileName + ".java\"; >> \"" + ""
+ "C:\\Users\\aookpidi\\Desktop\\testCompilerOutput.txt" + "\" 2>&1";
System.out.println("Compile student source command: "
+ compileCommand);
The compiler error I keep getting is:
javac: invalid flag: C:\submissions\SOFT222\junit-4.11.jar;
Usage: javac <options> <source files>
use -help for a list of possible options