【问题标题】:Absolute path on Xtext projectXtext 项目的绝对路径
【发布时间】:2017-06-02 18:54:13
【问题描述】:

我想知道如何获取在我的项目中而不是在运行的应用程序中的文件的绝对路径。

例如这个:

C:\Users\Mr\Documents\Example\org.xtext.example.mydsl\src\example.txt

我尝试过类似的路径:

val file = new File("relative path");
val absolutePathString = file.getAbsolutePath();

System.getProperty("user.dir");

但它们都检索到我的 Eclipse 路径,而不是我的项目路径。

感谢您的帮助!

【问题讨论】:

  • 你在eclipse里面吗?您处于独立模式吗?

标签: path xtext absolute-path xtend


【解决方案1】:

不需要有文件。假设您有一个带有默认文件系统的默认 eclipse 并谈论项目中的一个文件,您可能会看看这些

public void doit(Resource r) {
    URI uri = r.getURI();
    if (uri.isPlatformResource()) {
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true)));
        file.getLocation();
        file.getLocationURI();
        file.getRawLocation();
        file.getRawLocationURI();

    }
}

【讨论】:

  • 谢谢!但这不是我要找的。假设我有默认的 Xtext 项目,它识别你好名字!。甚至在运行应用程序之前,我想在我的项目上加载我的 ServiSegGenerator.xtend 上的 .txt 文件或项目中的 .java 类。我想将此文件放在 src/folder 上,但我无法获得该路径,因为我总是从正在运行的应用程序中获得 C:\eclipse 或路径。再次感谢您的时间^^
  • 好吧,但那是一个 class.getResource / class.getResourceAsStream 用例
  • 你指的是哪个项目
  • 如果你在独立模式下调用生成器会怎样
  • 嗨!我已经使用 class.getResourceAsStream 解决了它,然后在加载的文件上使用了 BufferedReader。这样比尝试获取 src 项目的完整路径更容易。谢谢!
猜你喜欢
  • 1970-01-01
  • 2016-05-08
  • 1970-01-01
  • 2013-08-25
  • 2011-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多