我需要编译一个外部 java 文件(比如 a.java)。这是我为此编写的代码。
(字符串路径包含java和class文件的路径)
command[0] = "javac";
command[1] = path+"a.java";
p = Runtime.getRuntime().exec(command);
上面的代码似乎工作得很好。但是下面的代码
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;
导致以下错误
java.lang.NoClassDefFoundError: a
Exception in thread "main"
有人可以解释这段代码的问题吗?谢谢 !