4

I write ant build script. I need to create a symlink and I found symlink task. According to manual, it works only on Unix. What happens if someone run my build script on windows platform? Will build fail? Or this task will be ignored on windows platform? Or in case of NTFS drive, it will even work?

kenorb
  • 155,785
  • 88
  • 678
  • 743
Dmytro Zavalkin
  • 5,265
  • 1
  • 30
  • 34

2 Answers2

3

I'm running Win7 and I tried it. Since I have Mingw installed it used ln. Ln seemed just to copy everything. Since a normal Windows installation does not have ln, it would fail there.

Here's what happens without ln:

C:\Users\Janus\Desktop>.\apache-ant-1.8.2\bin\ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
Buildfile: C:\Users\Janus\Desktop\build.xml

dist:

BUILD FAILED
C:\Users\Janus\Desktop\build.xml:3: Could not launch ln: java.io.IOException: Cannot run program "ln": CreateProcess error=2, The system can
not find the file specified

Total time: 1 second

C:\Users\Janus\Desktop>

Build.xml:

<project name="MyProject" default="dist" basedir=".">
<target name="dist">
<symlink link="lol" resource="d3dwindower" />
</target>
</project>
Janus Troelsen
  • 20,267
  • 14
  • 135
  • 196
  • Hmm, are you sure it will not try to use mklink if ln isn't found? And will it fail or will be silently ignored? Could you delete/rename your ln and check, please? – Dmytro Zavalkin Aug 05 '11 at 22:47
  • Thank you. Can you explain me part with `tools.jar`, please? What happen if tool.jar is present, it will emulate ln using some java code? – Dmytro Zavalkin Aug 06 '11 at 18:07
  • 1
    Quote from Ant docs: *When you need JDK functionality (such as for the javac task or the rmic task), then tools.jar must be added. The scripts supplied with Ant, in the bin directory, will add the required JDK classes automatically, if the JAVA_HOME environment variable is set.* I.e. I ran Ant using a JRE classpath. In this case it didn't matter because I didn't compile anything. Doesn't make any difference regarding symlinks. – Janus Troelsen Aug 07 '11 at 12:04
1

I created a condition property to identify if I am running on unix:

<condition property="isUnix">
  <os family="unix"/>
</condition>

and then use an 'if' attribute on my target so it will only execute if on unix:

<target name="makeSymLinkToJar" depends="jar" if="isUnix">
    <symlink link="${distlink.jar}" resource="${dist.jar}"/>
</target>
PeterVermont
  • 1,922
  • 23
  • 18
  • Sorry, but question is about what will happen while running symlink task on Win platform, not how to restrict task to run only on unix platform. – Dmytro Zavalkin Feb 02 '14 at 02:10
  • I got this warning: `makeSymLinkToJar: [symlink] cygwin warning: [symlink] MS-DOS style path detected: C:\dev\mdr-svn\dist/mdr.jar [symlink] Preferred POSIX equivalent is: /cygdrive/c/dev/mdr-svn/dist/mdr.jar [symlink] CYGWIN environment variable option "nodosfilewarning" turns off this warning. [symlink] Consult the user's guide for more details about POSIX paths: [symlink] http://cygwin.com/cygwin-ug-net/using.html#using-pathnames` It created a 1k file that looks like a corrupted jar file but may be a faulty symlink. Not sure what would happen without cygwin – PeterVermont Feb 03 '14 at 14:20