英文:
Get "eclipse-workspace" path in Java
问题
我在尝试在Java中获取Eclipse项目文件夹。
我尝试了以下代码,但没有成功。
String absolutePath = new File(".").getAbsolutePath();
System.out.println(absolutePath);
int last = absolutePath.length() - 1;
absolutePath = absolutePath.substring(0, last);
return absolutePath;
输出:
/home/itsdaniel/eclipse/
我想要的是:
/home/itsdaniel/eclipse-workspace
英文:
im trying to get the eclipse project folders in Java.
I tried the code below, but no luck.
String absolutePath = new File(".").getAbsolutePath();
System.out.println(absolutePath);
int last = absolutePath.length()-1;
absolutePath = absolutePath.substring(0, last)
return absolutePath;
output:
/home/itsdaniel/eclipse/
what I want:
/home/itsdaniel/eclipse-workspace
答案1
得分: 0
如前面的评论中所提到的,无法从由Eclipse自身启动的普通Java应用程序中访问Eclipse内部的工作区路径。
如果您想要访问这些信息,您需要编写一个简单的Eclipse插件。
如何操作?
- 下载RCP Eclipse,例如:https://www.eclipse.org/downloads/packages/release/2020-03/r/eclipse-ide-rcp-and-rap-developers
- 解压并启动RCP Eclipse
- 创建一个示例插件,我认为网上有足够的信息,例如:https://www.youtube.com/watch?v=GIweFZOf36E 详细描述了如何操作。
- 在创建的处理程序类中获取工作区路径位置 - 例如:
ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
英文:
As mentioned in the comments before, it is not possible to access the workspace path inside eclipse from a normal Java application started by Eclipse itself.
If you want to access such information you have to write a simple eclipse plugin.
How ?
- Download RCP eclipse, e.g: https://www.eclipse.org/downloads/packages/release/2020-03/r/eclipse-ide-rcp-and-rap-developers
- Unpack and start RCP eclipse
- Create an example plugin, I think there is enough information at the web, e.g. https://www.youtube.com/watch?v=GIweFZOf36E describes it very easy.
- Inside the created Handler class fetch the workspace path location - e.g.
ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
专注分享java语言的经验与见解,让所有开发者获益!
评论