是否可以在无头模式下使用JDT加载Eclipse Java项目? [英] Is it possible to load an eclipse Java project using JDT in the headless mode?

查看:138
本文介绍了是否可以在无头模式下使用JDT加载Eclipse Java项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个eclipse Java项目,想要获取项目源目录,类路径等信息.我当前的实现解析.project文件.但是由于找不到任何描述.project文件结构的官方文档,因此我对该方法的鲁棒性有所担忧.

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.

一种更方便,更可靠的方法是(无头)使用JDT加载项目并从IJavaProject对象获取相关信息.

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.

尽管JDT的开发人员指南说

Although the developer guide of JDT says

JDT Core软件包使您可以访问Java模型对象和无头Java IDE基础结构.

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

我可以找到的所有示例打开一个现有的Java项目,可以从workspace内的项目中获得IJavaProject对象,或者使用IProject对象.但是我找不到将项目添加到workspace或从.project文件的路径构造IProject/IJavaProject的方法.

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.

有人可以帮忙吗?

推荐答案

是的,并且都可以通过清晰且稳定的API来完成. org.eclipse.jdt.core是一个插件,就像(您将在其中获得IWorkspace实例的地方),并且它们都希望在 Eclipse运行时内的内部中运行,如果这是您编写的方式,则可能毫无头绪您的 Eclipse应用程序. JDT使用.classpath文件来记录源,库和构建输出的位置以及要使用的库的抽象引用,而.project文件是什么来记录其总体上是哪种项目-Java,PHP ,网络,这些功能或其他功能的某种组合-以及有关要执行哪些构建器的更多信息.

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.

因此,使自己成为一个无头的Eclipse应用程序,或将最终目标功能打包在其中.

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.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-

这篇关于是否可以在无头模式下使用JDT加载Eclipse Java项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆