Link to Files and Folders in Eclipse
Join the DZone community and get the full member experience.Join For Free
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.
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 n ew > file (or the menu file > new > other > general > file ):
that opens a dialog to create a new file. i can select which project/folder i want to use for this:
next, click on ‘advanced’, enable ‘link to file in the file system’ and browse to the file you want to link to:
this will set the link to the file:
as an absolute path (c:\….) is probably not really what you want, there are eclipse path variables you can use:
: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:
this now uses a path variable for that link. note that it shows as well to which file it resolves:
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:
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:
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:
- 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. :-)
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:
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:
: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:
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 :-).
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 :-)
Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Microservices With Apache Camel and Quarkus
Web Development Checklist
AI Technology Is Drastically Disrupting the Background Screening Industry