【问题标题】:Eclipse project - add linked resources programmaticallyEclipse 项目 - 以编程方式添加链接资源
【发布时间】:2014-01-12 09:27:15
【问题描述】:

.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()IProjectJavaDoc没有)
Eclipse Add marker for linked resources

相关:
Programmatically remove linked files from the project in 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
   }

【问题讨论】:

    标签: java eclipse eclipse-plugin nodeclipse eclipse-project-file


    【解决方案1】:

    您使用IFileIFoldercreateLink 方法来创建链接资源。

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

    // 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);
    

    【讨论】:

      【解决方案2】:

      您的一个链接问题实际上是使用IFoldercreateLink 方法引用example code

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多