Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse project - add linked resources programmatically

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
   }
like image 414
Paul Verest Avatar asked Apr 07 '26 06:04

Paul Verest


1 Answers

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

like image 194
Bananeweizen Avatar answered Apr 10 '26 02:04

Bananeweizen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!