Compiling a class using Java code using process

Posted by Noona on Stack Overflow See other posts from Stack Overflow or by Noona
Published on 2010-05-18T15:35:09Z Indexed on 2010/05/18 16:40 UTC
Read the original article Hit count: 223

Filed under:
|

I have this piece of code that compiles a class called tspClassName, when I compile using this code:

           Process compileProc = null;
        try {
            compileProc = Runtime.getRuntime().exec("javac -classpath ."
                       + File.separator + "src" + File.separator
                       + File.separator + "generated." + tspClassName + ".java -d ." + File.separator + "bin");
        // catch exception
           if (compileProc.exitValue() != 0) 
           {
               System.out.println("Compile exit status: "
                          + compileProc.exitValue());
                      System.err.println("Compile error:" +
                              compileProc.getErrorStream());

it outputs this: "Compile exit status: 2 Compile error:java.io.FileInputStream@17182c1" The class tspClassName.java compiles without errors otherwise, so I am guessing it has to do with the path,and in my eclipse project, the tspClassName.java resides in package homework4.generated inside src, is there something wrong with the path that I use in the code?

thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about compiler