有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

来自Eclipse应用程序的java工作区

我正在创建一个独立的eclipse应用程序,需要从该应用程序获取我的工作区。我不想要Eclipse插件,因为它不能解决我的问题

IWorkSpaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

但这给了我一个例外,因为工作区是关闭的。 无论是我当前的工作区,还是任何可以使用独立应用程序访问的新工作区,都可以解决我的问题


共 (2) 个答案

  1. # 1 楼答案

    在插件的Require包中Manifest.MF是否包含org.eclipse.core.resources

    您是否以插件的形式启动应用程序?(不是作为“Java应用程序”)

    You can access the workspace from the resources plugin class (defined in org.eclipse.core.resources).

    When the resources plug-in is not running, the workspace exists solely in the file system and is viewed or manipulated by the user via standard file-based tools. Let's look at what a workspace looks like on disk as we explain the resources plug-in API.

    有关更多详细信息,请参见Book

    As a Java application, you cannot use ResourcesPlugin functions. So you need to access resources through classic File resources.

  2. # 2 楼答案

    对于这个问题,我使用以下肮脏的解决方法。您需要手动更新RCP单机版的配置

    1. 打开“配置”。ini”文件位于“配置”文件夹中(项目位置下)
    2. 编辑配置中的最后一行。ini文件: osgi.instance.area.default=<Workspace Loc>
    3. 将行中的替换为工作区的位置
      e、 g.:osgi.instance.area.default=D:/WorkspaceFolder/WorkspaceNew

    重要提示:指定工作空间时,应使用正斜杠(/)作为分隔符