简体   繁体   English

如何以编程方式获取工作区?

[英]How to get workspace programmatically?

any one know how can I get current path of eclipse workspace programmatically. 任何人都知道如何以编程方式获取Eclipse工作区的当前路径。 Since this path changes in every computer I want to get this thing programmatically and dynamically. 由于此路径在每台计算机中都会发生变化,因此我想以编程方式和动态方式获取此内容。 It should return a string and it should be like ersin/projects/proj/my_work_space_name . 它应该返回一个字符串,并且应该类似于ersin/projects/proj/my_work_space_name

by the way this code didnt work for me: ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() it gives ersin/projects/proj/runtime-EclipseApplication whereas it should be ersin/projects/proj/my_work_space_name . 顺便说一下,这段代码对我不起作用: ResourcesPlugin.getWorkspace().getRoot().getLocation().toString()它给出了ersin/projects/proj/runtime-EclipseApplication而它应该是ersin/projects/proj/my_work_space_name

It looks like you're getting that value because you're running a test environment for debugging a plugin. 您似乎正在获得该价值,因为您正在运行用于调试插件的测试环境。 When you do that, you're effectively running a different workspace and that's why you're getting the root location of that workspace. 当您执行此操作时,您将有效地运行另一个工作空间,这就是为什么要获取该工作空间的根目录的原因。 Should you get to the point where you run that plugin in your original development workspace, you'll get the value you expect. 如果您可以在原始开发工作区中运行该插件,那么您将获得期望的价值。

In short, you are getting the current path of the eclipse workspace. 简而言之,您将获得Eclipse工作区的当前路径。

So if you're trying to debug a plugin that searches the workspace, you'll need to add projects to your test workspace so that the search can take place there. 因此,如果要调试搜索工作空间的插件,则需要将项目添加到测试工作空间,以便可以在此处进行搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM