How to make a symlink in Java when running in Linux?
Asked Answered
M

1

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.

Mendoza answered 2/2, 2011 at 7:22 Comment(1)
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: javaworld.com/jw-12-2000/jw-1229-traps.htmlPectoral
P
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.

Pectoral answered 2/2, 2011 at 7:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.