Pergunta

An example of .project contains

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

How to add linked resources programmatically?

org.eclipse.core.resources.IProjectDescription does not have related methods

IProjectDescription

So this Q mentions getLinks() for IProject (JavaDoc has no)
Eclipse Add marker for linked resources

Related to:
Programmatically remove linked files from the project in eclipse

UPDATED: Solved with help of both answers, as they brought understanding of Eclipse terminology (what is what)

Code

   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
   }
Foi útil?

Solução

One of your linked questions actually refers to example code using the createLink method of IFolder.

Outras dicas

You use the createLink methods of IFile and IFolder to create linked resources.

For a file you do two steps:

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

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

and much the same for a folder:

IFolder newFolder = project.getFolder(workspacePath);

newFolder.createLink(actualPath, flags, monitor);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top