3

.project包含的示例

<linkedResources>
    <link>
        <name>node_lib</name>
        <type>2</type>
        <location>E:/Nodejs/node-v0.10.22/node-v0.10.22/lib</location>
    </link>
</linkedResources>

如何以编程方式添加链接资源?

org.eclipse.core.resources.IProjectDescription没有相关方法

项目描述

所以这个Q提到getLinks()JavaDoc没有)Eclipse为链接资源添加IProject 标记

相关:以
编程方式从 Eclipse 中的项目中删除链接文件

更新:在两个答案的帮助下解决,因为它们带来了对 Eclipse 术语的理解(什么是什么)

代码

   IFolder link = project.getFolder("Link");
   IPath location = new Path("TEMP/folder");
   if (workspace.validateLinkLocation(location).isOK()) {
      link.createLink(location, IResource.NONE, null);
   } else {
      //invalid location, throw an exception or warn user
   }
4

2 回答 2

2

您的链接问题之一实际上是指使用createLink.IFolder

于 2013-12-24T08:15:39.387 回答
1

您使用 和 的方法createLink来创建链接资源。IFileIFolder

对于文件,您执行两个步骤:

// Get IFile for file
IFile newFile = project.getFile(workspacePath);

// Create the link
newFile.createLink(actualPath, flags, monitor);

和文件夹大致相同:

IFolder newFolder = project.getFolder(workspacePath);

newFolder.createLink(actualPath, flags, monitor);
于 2013-12-24T08:13:44.307 回答