Re: Eclipse components
- From: Roland <roland@xxxxxxxxx>
- Date: Thu, 28 Jul 2005 20:37:53 +0200
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_/ /__/ / \ /_/ / \ .
- References:
- Eclipse components
- From: Tim Tyler
- Eclipse components
- Prev by Date: Re: Logging Strategy/best practice
- Next by Date: Re: Is a static method sufficient to call it factory?
- Previous by thread: Re: Eclipse components
- Next by thread: About Apache Maven scm plugin
- Index(es):
Relevant Pages
|