想问下 Runtime.getRuntime().exec(command, env);中env
具体应该怎么设置,
具体我在一个项目中 
command = "javac -nowarn \"" + className + "\" -d \""
+ compiledStubPath + "\" -sourcepath \"" + stubPath + "\"";
String[] env = {"CLASSPATH=" + System.getProperty("java.class.path")
+ File.pathSeparatorChar + libPath};但是不成功想问应该怎么设置

解决方案 »

  1.   

    你可以这样,在外面 写好一个 bat文件, 然后在程序中调用这个  bat 文件
      

  2.   

    但是 我的命令参数是动态生成的 所以不能写在bat文件
      

  3.   

    把执行的javac命令的错误消息先打印出来再看有什么问题吧~Runtime run = Runtime.getRuntime();
    Process p = run.exec("xxxxxxx");
    BufferedInputStream in = new BufferedInputStream(p.getInputStream());
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String s = null;
    while ((s = br.readLine()) != null)
        System.out.println(s); 
      

  4.   

     public     void   runBat(String parm)    {
             String command  =   "  run.bat   "   +  parm;
              try       {
                Process child   =   Runtime.getRuntime().exec(command);
                  }  
              catch   (Exception ex)
                {
                ex.printStackTrace();
                 }      
        }   
      

  5.   

    楼主的意思应该是先设置环境变量吧!
    建议动态生成bat文件,再调用
      

  6.   

    我也遇到runtime问题,不过我是传入的命令不执行,有啥看法?编译运行都不报错,就是没结果
      

  7.   


    String c = "java -classpath E:/workspace/t/bin/ T1";
    Process exec = Runtime.getRuntime().exec(c);
    BufferedReader r = new BufferedReader(new InputStreamReader(exec.getInputStream()));
    System.out.println(r.readLine());
    exec.waitFor();我写了这段代码,是对的,可以输出T1类的输出,你参考一下