Generate bytecode from Eclipse CompilationUnit

I'm working on a project Eclipse plugin is not ; however, I am using an external library that generates an instance of org.eclipse.jdt.core.dom.CompilationUnit. Is there a way to generate Java bytecode from it?

In some searches, it turned out that CompilationUnit is usually created by registering a custom builder for an Eclipse project and then allowing eclipse to call it ... but I could not find any way to use this for a standalone application.

+3
source share
2 answers

The Partial Program Analysis for Java tool can theoretically do this using the class PPAUtil:

PPAUtil.compileCU(myCompilationUnit, baseOutputFolder)

Although in practice, he expects only instances CompilationUnitthat he creates with help PPAUtil.getCU(file, options, reqName, false), so I don’t know if he will work with an instance CompilationUnitthat was not created in this way.

0
source

I suggest looking at the code in Apache Commons JCI . It implements the eclipse compiler for stand-alone applications.

+1
source

Source: https://habr.com/ru/post/1727152/


All Articles