获取Java中的“eclipse-workspace”路径。

huangapple 未分类评论46阅读模式
英文:

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插件。

如何操作?

  1. 下载RCP Eclipse,例如:https://www.eclipse.org/downloads/packages/release/2020-03/r/eclipse-ide-rcp-and-rap-developers
  2. 解压并启动RCP Eclipse
  3. 创建一个示例插件,我认为网上有足够的信息,例如:https://www.youtube.com/watch?v=GIweFZOf36E 详细描述了如何操作。
  4. 在创建的处理程序类中获取工作区路径位置 - 例如: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 ?

  1. Download RCP eclipse, e.g: https://www.eclipse.org/downloads/packages/release/2020-03/r/eclipse-ide-rcp-and-rap-developers
  2. Unpack and start RCP eclipse
  3. 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.
  4. Inside the created Handler class fetch the workspace path location - e.g. ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();

huangapple
  • 本文由 发表于 2020年4月7日 05:39:06
  • 转载请务必保留本文链接:https://java.coder-hub.com/61069383.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定