Example usage for org.eclipse.jdt.internal.compiler.batch Main compile

List of usage examples for org.eclipse.jdt.internal.compiler.batch Main compile

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.batch Main compile.

Prototype

public static boolean compile(String commandLine, PrintWriter outWriter, PrintWriter errWriter) 

Source Link

Usage

From source file:org.appcelerator.locator.ServiceCompiler.java

License:Apache License

/**
 * compile a service file written in Java
 * //from  ww  w.  j  av  a2  s  . c om
 * @param serviceFile
 * @param classDir
 */
public static boolean compileJava(File serviceFile, File classDir, PrintWriter stderr) {
    if (LOG.isDebugEnabled())
        LOG.debug("compiling java service file: " + serviceFile);

    classDir.mkdirs();

    URL[] urls = ClasspathUrlFinder.findClassPaths();
    StringBuilder cp = new StringBuilder();
    cp.append("\"" + System.getProperty("sun.boot.class.path") + "\"");
    cp.append(File.pathSeparatorChar);
    for (URL url : urls) {
        cp.append("\"");
        cp.append(url.getPath());
        cp.append("\"");
        cp.append(File.pathSeparatorChar);
    }
    StringWriter errWriter = new StringWriter();
    StringBuffer buf = errWriter.getBuffer();

    // calculate the source version to use with the compiler. we support a new custom system 
    // property called java.compiler.version which can be set to specifically use a different version
    // otherwise we default to 1.5
    String ver = System.getProperty("java.compiler.version", "1.5");

    boolean success = Main
            .compile(
                    "-g -source " + ver + " -cp " + cp + " -d " + classDir + " \""
                            + serviceFile.getAbsolutePath() + "\"",
                    new PrintWriter(System.out, true), new PrintWriter(errWriter, true));

    stderr.print(buf.toString());
    stderr.flush();

    return success;
}