I';我在运行使用javax.tools.JavaCompiler编译的代码时遇到了问题

I';我在运行使用javax.tools.JavaCompiler编译的代码时遇到了问题,java,javacompiler,Java,Javacompiler,我正在做我的第一个java项目,也就是一个文本编辑器,它也可以编译和运行文件。编译器(javax.tools.JavaCompiler)运行得很好,但是当我尝试运行“.class”文件时,什么都没有显示。我需要帮助 以下是编译代码: public void compileIt(String s) //s is the absolute path of file to be compiled { JavaCompiler compiler = ToolProvide

我正在做我的第一个java项目,也就是一个文本编辑器,它也可以编译和运行文件。编译器(javax.tools.JavaCompiler)运行得很好,但是当我尝试运行“.class”文件时,什么都没有显示。我需要帮助

以下是编译代码:

public void compileIt(String s)     //s is the absolute path of file to be compiled
    {
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        MyDiagnosticListener listener = new MyDiagnosticListener();
             StandardJavaFileManager fileManager =
                compiler.getStandardFileManager(listener, null, null);

        File file;
        file = new File(s);
         String classOutputFolder ="E:\\codefiles";  //destination for storing .class files

        Iterable<? extends JavaFileObject> javaFileObjects = fileManager.getJavaFileObjects(file);
        Iterable options = Arrays.asList("-d", classOutputFolder);
        JavaCompiler.CompilationTask task =
                compiler.getTask(null, fileManager, listener, options, null, javaFileObjects);
        if (task.call()) {
            System.out.println("compilation done");
        }
        try {
            fileManager.close();
        } catch (IOException ex) {
            Logger.getLogger(getName()).log(Level.SEVERE, null, ex);
        }
    }

原因之一是

 Process p = Runtime.getRuntime().exec("java -cp E:\\codefiles");
不起作用的原因是命令行语法错误。您还需要提供一个类名;e、 g

 Process p = Runtime.getRuntime().exec(
        "java -cp E:\\codefiles  com.example.MyMain");
这假设您试图运行的类有一个合适的
main
方法

 Process p = Runtime.getRuntime().exec("java -cp E:\\codefiles");
不起作用的原因是命令行语法错误。您还需要提供一个类名;e、 g

 Process p = Runtime.getRuntime().exec(
        "java -cp E:\\codefiles  com.example.MyMain");
这假设您试图运行的类具有合适的
main
方法