简体   繁体   English

使用Java将文件导入为Eclipse项目的链接

[英]Importing files as link to Eclipse project using Java

My Eclipse plugin needs files imported as link to the current project. 我的Eclipse插件需要导入的文件作为当前项目的链接。

The current approach is to drag and drop the file from explorer and use the following settings: 当前的方法是从资源管理器拖放文件并使用以下设置:

在此输入图像描述

I want to achieve the same using my SWT window without the user showing the popup seen in the picture above but rather my own SWT window. 我希望使用我的SWT窗口实现相同的目的,而不是用户显示上图中看到的弹出窗口,而是我自己的SWT窗口。 It is currently checking if the file exists somewhere on the disc and asks if it's the right file and project ( IProject ) to copy into (here starts the trouble). 它目前正在检查文件是否存在于光盘的某个位置,并询问它是否是要复制到的正确文件和项目( IProject )(这里开始出现问题)。

I could copy the file to the current workspace folder as I already have the project name ( IProject ) and could get the (changing) workspace folder by code somehow too. 我可以将文件复制到当前工作区文件夹,因为我已经拥有项目名称( IProject ),并且可以通过代码以某种方式得到(更改)工作区文件夹。 But those files wouldn't actually be links. 但那些文件实际上不是链接。

Are there any ways of doing it inside Eclipse rather than copying files at the OS level and achieving a link somehow? 是否有任何方法可以在Eclipse中执行此操作,而不是在操作系统级别复制文件并以某种方式实现链接?

Read this link. 阅读此链接。 http://help.eclipse.org/juno/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/resInt_linked.htm . http://help.eclipse.org/juno/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/resInt_linked.htm

Explained clearly on how to create Link files programmatically. 清楚地解释了如何以编程方式创建链接文件。 If in case I understood your question wrongly, let me know. 如果我错误地理解你的问题,请告诉我。

Updated based on comments received 根据收到的意见更新

Snippet from the Link which explains how Link files shall be created programatically. 链接的片段解释了如何以编程方式创建链接文件。

IProject project = workspace.getProject("Project");//assume this exists
IFolder link = project.getFolder("Link");
IPath location = new Path("C:\\temp\\folder");
    if (workspace.validateLinkLocation(link , location).isOK()) {
    try {
        link.createLink(location, IResource.NONE, null);
    } catch (CoreException e) {
        e.printStackTrace();
    }   
    } else {
      //invalid location, throw an exception or warn user
    }

You now have a linked folder in your workspace called "Link" that is located at "c:\\temp\\folder". 您现在在工作区中有一个名为“链接”的链接文件夹,位于“c:\\ temp \\ folder”。

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

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