我有两个项目——try.java 和另一个.java。我想从 try.java 运行另一个 java
这是我的 another.java 代码
package another;
public class Another {
public static void main(String[] args)
{
System.out.println("Another Java Project");
}
}
这是try.java的mycode
package pkgtry;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Try
{
private static void printLines(String name, InputStream ins) throws Exception {
String line = null;
BufferedReader in = new BufferedReader(new InputStreamReader(ins));
while ((line = in.readLine()) != null)
{
System.out.println(name + " " + line);
}
}
private static void runProcess(String command) throws Exception
{
Process pro = Runtime.getRuntime().exec(command);
printLines(command + " stdout:", pro.getInputStream());
printLines(command + " stderr:", pro.getErrorStream());
pro.waitFor();
System.out.println(command + " exitValue() " + pro.exitValue());
}
public static void main(String[] args)
{
try
{
runProcess("javac C:\\Users\\owner\\Documents\\NetBeansProjects\\try\\src\\pkgtry\\Another.java");
runProcess("java C:\\Users\\owner\\Documents\\NetBeansProjects\\try\\src\\pkgtry\\Another");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
运行 Try.java 后它没有打印任何东西。它只是在netbeans中成功打印构建。但是已经创建了一个类 Another.cass
谁能帮我?