Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to load an eclipse Java project using JDT in the headless mode?

I have an eclipse Java project and want to get information like project source dir, classpaths, etc. My current implementation parses the .project file. But as I didn't find any official documentation describing the structure of the .project file, I have some concerns for the robustness of this approach.

A more convenient and robust way would be to use JDT (headlessly) to load the project and get the relevant information from the IJavaProject object.

Although the developer guide of JDT says

JDT Core packages give you access to the Java model objects and headless Java IDE infrastructure.

all the examples I can find opening an existing Java project get the IJavaProject object from projects within a workspace or use an IProject object. But I couldn't find the way to add a project to the workspace or to construct a IProject/IJavaProject from a path to .project file.

Could anyone please help?

like image 608
MYP Avatar asked Jan 22 '26 19:01

MYP


1 Answers

Yes, and can all be done through clear and stable API. org.eclipse.jdt.core is a plug-in, just like org.eclipse.core.resources (which is where you would get an IWorkspace instance), and they both expect to be running within an Eclipse runtime, which can be headless if that's how you write your Eclipse Application. JDT uses the .classpath file to record where sources, libraries, and build output are, and what abstracted references to libraries to use, while the .project file is what records what kind of project it is in general--Java, PHP, Web, some combination of those or others--and a little more information about what builders to execute.

So make yourself a headless Eclipse Application, or package your end-goal functionality inside of one.

https://wiki.eclipse.org/FAQ_What_is_an_Eclipse_application%3F https://wiki.eclipse.org/FAQ_What_are_extensions_and_extension_points%3F http://help.eclipse.org/mars/topic/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_core_runtime_applications.html?cp=2_1_1_27

http://help.eclipse.org/mars/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/core/resources/ResourcesPlugin.html#getWorkspace-- http://help.eclipse.org/mars/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/JavaCore.html#getJavaCore-- http://help.eclipse.org/mars/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/IJavaProject.html#getResolvedClasspath-boolean-

like image 122
nitind Avatar answered Jan 24 '26 11:01

nitind