Overview
This project provides two Ant tasks, <createlink>
and <deletelink>
, for creating and deleting symbolic links, respectively.
Unlike Ant's built-in <symlink>
task, these tasks are implemented using Java 7 NIO APIs, making them more cross-platform than the built-in task.
These tasks are also more straightforward (as in, they do not have as many options).
Assuming you have built the project (using Ant and build.xml
, part of the project), you can copy the output artifact fslink.jar
into your project's source tree.
For example:
<taskdef name="createlink"
classname="io.github.cbrown06.fslink.CreateLinkTask"
classpath="fslink.jar"/>
<taskdef name="deletelink"
classname="io.github.cbrown06.fslink.DeleteLinkTask"
classpath="fslink.jar"/>
The <createlink>
task creates a link pointing to a resource, optionally overwriting any existing resource.
It can be configured to either fail on error (halting the build), or just echo a warning.
Usage is as follows:
<createlink failonerror="true"
overwrite="false"
link="link-to-create"
resource="regular-file"/>
The <deletelink>
task deletes a link pointing to a resource, doing nothing if no such link exists.
It will not delete regular files.
It can be configured to either fail on error (halting the build), or just echo a warning.
Usage is as follows:
<deletelink failonerror="true"
link="link-to-delete"/>
Usage with Windows
Unlike the <symlink>
task provided by Ant, these tasks do not try to invoke the ln
shell command
(which will by default cause a build script to fail on Windows). Standard cross-platform Java7+ NIO APIs are used instead.
However, even if these tasks are implemented using cross-platform APIs, when used with Windows, you must ensure that the user executing the build script has appropriate privileges (this is not the case by default). Windows permissions are granted using the Group Policy Editor (which may require you to log out and then back in again).
Start gpedit.msc
from the Windows Command Prompt, and then grant permissions via
Computer configuration >
Windows Settings >
Security Settings >
Local Policies >
User Rights Assignment >
Create symbolic links (see this screenshot).
You may need to log out of your Windows session and then log back in again (or use the gpupdate
command) for these permissions to be effective.
You will also need to run Ant as an administrator (for example, from the Start Menu, right-click "Command Prompt" and click on "Run as administrator"). None of this is necessary on non-Windows operating systems.