Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Doc about EclipseCompiler for JSR 199?(How can I set warning and related options using the JavaCompiler interface?)
Doc about EclipseCompiler for JSR 199? [message #1839111] Sun, 14 March 2021 17:55
Olivier Cailloux is currently offline Olivier CaillouxFriend
Messages: 36
Registered: July 2009
Member
I have been successfully using EclipseCompiler as an instance of JavaCompiler, to compile Java classes in memory.

Here is a sample code.

JavaCompiler compiler = new EclipseCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(fileDiagnostics, Locale.US, StandardCharsets.UTF_8);
fileManager.setLocationFromPaths(StandardLocation.ANNOTATION_PROCESSOR_PATH, ImmutableList.of());
fileManager.setLocationFromPaths(StandardLocation.CLASS_PATH, classPath);
fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, ImmutableSet.of(outputDirectory));
StringWriter compilationOutputReceiver = new StringWriter();
boolean compiled = compiler.getTask(compilationOutputReceiver, fileManager, compilerDiagnostics, ImmutableList.of(), null, fileManager.getJavaFileObjectsFromPaths(sourcePaths)).call();
String compilationOutput = compilationOutputReceiver.toString();


I use org.eclipse.jdt:ecj:3.24.0, which defines org.eclipse.jdt.internal.compiler.tool.EclipseCompiler.

Can I find some documentation about this implementation of JSR 199? (I have read Compiling Java code but I do not think it is related to what I try to do as the code I want to compile is not in an Eclipse workspace and I am not developing an Eclipse plug-in.)

In particular, I wonder how to pass this compiler an equivalent of the option -properties <file> that can be used with the batch compiler. Other things I wonder about are what Eclipse will give me (by contract) as file manager diagnostics; as compile task diagnostics; and as mere output (compilationOutput in my code sample).

Is there some documentation about all this somewhere? Or should I use another jar for accessing Eclipse's implementation of JSR 199? (I am also a bit puzzled by the EclipseCompiler being in an "internal" package.)

[Updated on: Sun, 14 March 2021 17:57]

Report message to a moderator

Previous Topic:Problem with Java ACM or JDK
Next Topic:Eclipsed locked up again
Goto Forum:
  


Current Time: Mon Jun 14 07:21:27 GMT 2021

Powered by FUDForum. Page generated in 0.01439 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top