在java的main方法中调用java和javac

2014-11-23 21:27:00 · 作者: · 浏览: 58

  调用java:


  Runtime hello=Runtime.getRuntime(); //Runtime构造函数私有,只能通过这种方式获得实例。


  hello.exec("cmd /c start Java -D org.apache.axis.wsdl.WSDL2Java http://www.scottnichol.com/samples/hellowsdl2.php wsdl");


  调用javac:


  com.sun.tools.javac.Main javac = new com.sun.tools.javac.Main(); //这个包在tools.jar中。


  String[] cpargs = new String[] {"-d", "所在目录","Temp.java"};


  int status = javac.compile(cpargs);


  if(status!=0){


  System.out.println("没有成功编译源文件!");


  return null;


  }