I am looking to create symlinks (soft links) from Java on a Windows Vista/ 2008 machine. I\'m happy with the idea that I need to call out to the JNI to do this. I am after h
Symbolic links in Windows are created using the CreateSymbolicLink API Function, which takes parameters very similar to the command line arguments accepted by the Mklink command line utility.
Assuming you're correctly referencing the JNI and Win32 SDK headers, your code could thus be as simple as:
JNIEXPORT jboolean JNICALL Java_ClassName_MethodName
(JNIEnv *env, jstring symLinkName, jstring targetName)
{
const char *nativeSymLinkName = env->GetStringUTFChars(symLinkName, 0);
const char *nativeTargetName = env->GetStringUTFChars(targetName, 0);
jboolean success = (CreateSymbolicLink(nativeSymLinkName, nativeTargetName, 0) != 0);
env->ReleaseStringUTFChars(symLinkName, nativeSymLinkName);
env->ReleaseStringUTFChars(targetName, nativeTargetName);
return success;
}
Note that this is just off the top of my head, and I haven't dealt with JNI in ages, so I may have overlooked some of the finer points of making this work...