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 Go to next message
Olivier Cailloux is currently offline Olivier CaillouxFriend
Messages: 40
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

Re: Doc about EclipseCompiler for JSR 199? [message #1844887 is a reply to message #1839111] Tue, 28 September 2021 20:15 Go to previous messageGo to next message
Ben Ferguson is currently offline Ben FergusonFriend
Messages: 1
Registered: September 2021
Junior Member
Hello! Have you received any response to this?

I am trying to use the eclipse java compiler to compile our code in batch, but am struggling to find any documentation on it.

If you have found a solution for that, I'd love to hear what you did.

Thanks!
Re: Doc about EclipseCompiler for JSR 199? [message #1844920 is a reply to message #1844887] Wed, 29 September 2021 16:19 Go to previous message
Olivier Cailloux is currently offline Olivier CaillouxFriend
Messages: 40
Registered: July 2009
Member
I'd love to have a positive answer. Unfortunately, I am still at the same point, no clue about how to use this compiler apart from trial and error.
Previous Topic:Java Compiler Error
Next Topic:New and already an error
Goto Forum:
  


Current Time: Tue Jan 18 11:31:42 GMT 2022

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

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

Back to the top