Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Link to Files and Folders in Eclipse

DZone's Guide to

Link to Files and Folders in Eclipse

· Java Zone
Free Resource

Are you joining the containers revolution? Start leveraging container management using Platform9's ultimate guide to Kubernetes deployment.

Eclipse projects have the nice features that they can link to files and folders: so instead of having the physical file, it is just a pointer to a file. This is very cool as that way I can point to shared files, or keep files in a common place referenced from projects, and so on.

Linked Folder and File in Eclipse

Linked Folder and File in Eclipse

As with most things in Eclipse, there is not a single way how to do things. So I’m showing in this post several ways how to link to files and folders.

Creating a New Link

Select the folder/project where to create a link to a file. Use the context menu with New > File (or the menu File > New > Other > General > File):

New File

New File

That opens a dialog to create a new file. I can select which project/folder I want to use for this:

New File Dialog

New File Dialog

Next, click on ‘Advanced’, enable ‘Link to file in the file system’ and Browse to the file you want to link to:

Link to File

Link to File

This will set the link to the file:

Specified link to file

Specified link to file

As an absolute path (C:\….) is probably not really what you want, there are Eclipse Path Variables you can use:

Path Variables

Path Variables

:idea: Note that these are Eclipse PATH variables (not Eclipse BUILD variables), see “Eclipse Build Variables“.

To use the Path Variable for the link, use the ‘Extend…’ Button and then select the file, then press OK:

Extending Path Variable

Extending Path Variable

This now uses a PATH variable for that link. Note that it shows as well to which file it resolves:

Resolved path variable for linked file

Resolved path variable for linked file

Press Finish, and the link will be created. Note the small ‘arrow’ in the icon (see “Icon and Label Decorators in Eclipse“) to show a linked file:

Linked File

Linked File

Modifying a Link

If you right-click on that linked file and select ‘Properties’ of it, you can see that it is really a Linked File, with the link information, and you can change/Edit that link any time:

Linked File Properties

Linked File Properties

Linked Folder

As for link to files, its possible to create ‘link to folders’. It works the same way: select the folder, then use File > New > Folder:

Creating new Folder

Creating new Folder

  • Use default location: this creates a normal folder.
  • Virtual Folder: this does not create a physical folder, but a virtual ‘container’ where I can place links or other virtual folders. This is useful to organize links and virtual folders, without the need for a physical folder.
  • Linked Folder: like linked files, this links to a folder.

:idea: The cool thing about linked (source) folders is: when I add new files to that folder where it links to, the projects with that linked folder to it will ‘see’ the extra files too, and that way new files are automatically added to the project. I do this many times, and it is like a ‘library’ folder for me: I can add a new source file to that ‘library’ folder, and every project linking to that folder will automatically have it added. :-)

Deleting Links

Linked files and linked folders can be deleted from the project too. In that case, the destination of the link is *not* deleted, only the link:

Deleting a Link to a Folder

Deleting a Link to a Folder

Using Drag & Drop

As mentioned at the beginning: there are multiple ways to do the same thing in Eclipse. Instead using the top menu, or using the context menu, I can use drag & drop. To create links, I need to hold the CTRL key:

Drag and Drop with CTRL pressed to create a link

Drag and Drop with CTRL pressed to create a link

:idea: Notice that during the drag&drop with CTRL key pressed the icon gets a ‘+’ to show copy/linking mode.

When I drop the file: I get the usual choices how I want to create the link:

Link to files and Folders Dialog

Link to files and Folders Dialog

Drag&Drop of files and folders do not work inside Eclipse. What works as well under Windows is to drag&drop a file or folder from the Windows Explorer :-).

Summary

Links to files and folders are a cool thing in Eclipse, and they can be created with menus or even simpler with drag&drop. This is not limited to inside Eclipse: I can drag&drop from outside with the Windows Explorer and that way can link to files and folders everywhere :-)

Happy Linking :-)

Using Containers? Read our Kubernetes Comparison eBook to learn the positives and negatives of Kubernetes, Mesos, Docker Swarm and EC2 Container Services.

Topics:

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}