12

Some time ago I wrote an Eclipse plugin which makes use of JDT to do some parsing. Now I am thinking of making a command-line version of this app. Naturally, I hope to reuse the parsing code, so I need to get JDT to work outside Eclipse. Is there any way I can accomplish this (maybe build some wrappers, etc)? Are there any ports of the JDT library that provide the same API / functionality but work independently of Eclipse?

Any help will be greatly appreciated. Thanks.

alexloh
  • 1,606
  • 2
  • 15
  • 29
  • I am parsing source code to get its structure (Abstract Syntax Tree). This link shows precisely what I am talking about (http://www.vogella.de/articles/EclipseJDT/article.html). Something like Antlr, etc, except that I already wrote the code with JDT, and I want to reuse it instead of rewriting with Antlr. Sorry I think I didnt make it clear – alexloh Jan 22 '10 at 04:09
  • hi @alexloh, did you get a solution for this? it would be great if you can explain how you accomplished this with some extra information? – Jugi Dec 10 '19 at 12:33

3 Answers3

4

You can use JDT Core in the command line. Parsing, AST, rewriting everything can be done without the UI.

Prakash G. R.
  • 4,746
  • 1
  • 24
  • 35
  • You need to dig into the docs and classes to find out the right calls. Eg: http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-230.htm – Prakash G. R. Feb 10 '14 at 18:05
4

The JDT is divided into two distinct parts. The parsing parts should all be in plugins which have no UI-dependencies at all. I think they do have a dependency on the Eclipse runtime, which means that you more or less need to create a "headless RCP application".

JesperE
  • 63,317
  • 21
  • 138
  • 197
  • Hmm I can't give "Accepted answer" to both :( Both this post and the one below are useful, and searching for "headless RCP application" put me on what seems to be the right track. Thanks! – alexloh Jan 24 '10 at 19:00
2

In order to be able to use AST classes in a stand alone application you have to use such libraries (where xx stands for version):

org.eclipse.core.contenttype_xx.jar
org.eclipse.core.jobs_xx.jar
org.eclipse.core.resources_xx.jar
org.eclipse.core.runtime_xx.jar
org.eclipse.equinox.common_xx.jar
org.eclipse.equinox.preferences_xx.jar
org.eclipse.jdt.core_xx.jar
org.eclipse.osgi_xx.jar

If you installed eclipse with JDT all those jars are in eclipse's plugin folder for example in Windows it could be in C:\Program Files\eclipse\plugins\

Templar
  • 1,843
  • 7
  • 29
  • 42