Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a symlink in Java when running in Linux?

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.

like image 213
Juha Syrjälä Avatar asked Feb 02 '11 07:02

Juha Syrjälä


People also ask

How do I create a symbolic link to a directory in Linux?

Ln Command to Create Symbolic Links By default, the ln command creates a hard link. Use the -s option to create a soft (symbolic) link. The -f option will force the command to overwrite a file that already exists. Source is the file or directory being linked to.

How do you create a symbolic link in Unix?

To create a symbolic link, use the -s ( --symbolic ) option. If both the FILE and LINK are given, ln will create a link from the file specified as the first argument ( FILE ) to the file specified as the second argument ( LINK ).

What is Linux symbolic link?

A symlink is a symbolic Linux/ UNIX link that points to another file or folder on your computer, or a connected file system. This is similar to a Windows shortcut. Symlinks can take two forms: Soft links are similar to shortcuts, and can point to another file or directory in any file system.


1 Answers

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.

like image 122
Joachim Sauer Avatar answered Sep 18 '22 14:09

Joachim Sauer