3

I am not working on an Eclipse plug-in project; however, I use an external library that generates an instance of org.eclipse.jdt.core.dom.CompilationUnit. Is there a way to generate Java bytecode from it?

Some searching revealed that CompilationUnit's are typically built by registering a custom builder for the Eclipse project, then letting eclipse invoke it... but I couldn't find any way to leverage that for a stand-alone application.

Oak
  • 26,231
  • 8
  • 93
  • 152
  • Maybe you should clearify your question ... what exactly do you want to know? Is it related to byte code generation? To leverage JDT from standaone application? Something else? – Arne Deutsch Jan 06 '10 at 07:24

2 Answers2

1

I suggest to have a look at the code in Apache Commons JCI. It implements an eclipse compiler for standalone applications.

tcurdt
  • 14,518
  • 10
  • 57
  • 72
  • I looked and it can convert an ICompilationUnit (which is surprisingly not related to CompilationUnit). However, it does seem like a good tool which takes me in the right direction, so thanks! – Oak Jan 07 '10 at 21:49
0

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

PPAUtil.compileCU(myCompilationUnit, baseOutputFolder)

Though in practice it only expects CompilationUnit instances it creates by itself with PPAUtil.getCU(file, options, reqName, false), so I don't know if it will work on a CompilationUnit instance not produced this way.

Oak
  • 26,231
  • 8
  • 93
  • 152