17

How to make a symlink in Java/JVM when running in Linux? Are there any other ways to this than using Java Native Interface (JNI) or java.lang.Runtime.exec("/bin/ln -s /some/path symlink")?

Creating a symlink is very platform dependant, but I mostly care about running on Linux, nice bonus would be if a shortcut would be created in Windows.

Juha Syrjälä
  • 32,255
  • 31
  • 127
  • 179
  • Also: if you want to use `Runtime.exec()`, then make sure to use the version that takes an array, or you get nasty suprises. Also, follow the advice here: http://www.javaworld.com/jw-12-2000/jw-1229-traps.html – Joachim Sauer Feb 02 '11 at 07:28

1 Answers1

30

The JDK 7 includes (via NIO.2) a class called Files that provides a createSymbolicLink() method.

Previous versions don't provide any built-in way to produce that, so JNI or Runtime.exec() are your only real options.

Joachim Sauer
  • 291,719
  • 55
  • 540
  • 600