I need to compile an external java file (say a.java). This is the code i wrote for the same.
(String path contains the path to the java and class file)
command[0] = "javac";
command[1] = path+"a.java";
p = Runtime.getRuntime().exec(command);
The above code seems to work just fine. But the below code
command[0] = "java";
command[1] = "a";
command[2] = "-cp";
command[3] = "."+path+"a";
p = Runtime.getRuntime().exec(command);
stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((temp = stdInput.readLine()) != null) result += "\n" + temp;
while ((temp = stdError.readLine()) != null) result += "\n" + temp;
Causes the following error
java.lang.NoClassDefFoundError: a
Exception in thread "main"
Could someone explaine the problem with this code. Thanks !