Re: Eclipse components



On 28-7-2005 14:19, Tim Tyler wrote:
Are the Eclipse compiler and formatter available as stand-alone
components yet?

If not why not?  Is it something to do with being big and blue?
Or do they not want their competitors using these components?

In one of our projects I've used the Eclipse compiler to compile a batch of Java files. This works perfectly. [Never used formatter stand-alone.]


You'll need the 'JDT Core' plugin: I've used org.eclipse.jdt.core_3.0.1, in particular the class org.eclipse.jdt.internal.compiler.batch.Main in jdtcore.jar. The following snippet shows how this class can be used


import org.eclipse.jdt.internal.compiler.batch.Main

/**
 * Compiles sourceFile and produces .class file in outDir.
 * @param sourceFile source file to compile
 * @param outDir directory of resulting class file
 * @return <code>true</code> if compilation was successful,
 *         <code>false</code> when compilation failed
 */
private boolean compileJavaSource(File sourceFile, File outDir)
{
  StringWriter javacOut = new StringWriter();
  PrintWriter pwJavacOut = new PrintWriter(javacOut);
  StringWriter javacErr = new StringWriter();
  PrintWriter pwJavacErr = new PrintWriter(javacErr);

  Main javac = new Main(pwJavacOut, pwJavacErr, false);

  String[] args = {"-d", outDir.toString(), sourceFile.toString()};

  boolean compiled = javac.compile(args);
  pwJavacOut.close();
  pwJavacErr.close();

  if (compiled)
  {
     // success
     return true;
  }
  else
  {
    // failed: log compiler messages
    __logger.severe("Java compiler stdout: " + javacOut.toString());
    __logger.severe("Java compiler stderr: " + javacErr.toString());
    return false;
  }
}

--
Regards,

Roland de Ruiter
` ___      ___
`/__/ w_/ /__/
/  \ /_/ /  \
.



Relevant Pages

  • Re: Inserting italics into my title in a custom class file
    ... I then opened the file sampleThesis.tex (included with the class file) ... everything compiles fine. ... you don't confuse it with the original) with ... that the abstract environment was getting some information from the ...
    (comp.text.tex)
  • Re: class names with "$"..
    ... > source code file called 'Connect.java' I get these three classes... ... Your class contains anonymous inner classes, each of these compiles to its ... own class file. ... Prev by Date: ...
    (comp.lang.java.help)
  • Re: Inserting italics into my title in a custom class file
    ... Callandor wrote: ... and run texhash. ... I then opened the file sampleThesis.tex (included with the class file) ... everything compiles fine. ...
    (comp.text.tex)