I am working on a java application.
I want to create desktop shortcut of my application's Exe file.
Is is possible to do it from my application itself ? Or user has to do it manually by right clicking ?
I am working on a java application.
I want to create desktop shortcut of my application's Exe file.
Is is possible to do it from my application itself ? Or user has to do it manually by right clicking ?
package farzi;
import net.jimmc.jshortcut.JShellLink;
public class Sc {
JShellLink link;
String filePath;
public Sc() {
try {
link = new JShellLink();
filePath = JShellLink.getDirectory("")
+ "C:\\Program Files\\Internet Explorer\\iexplore.exe";
} catch (Exception e) {
}
}
public void createDesktopShortcut() {
try {
link.setFolder(JShellLink.getDirectory("desktop"));
link.setName("ie");
link.setPath(filePath);
link.save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String a[]) {
Sc sc = new Sc();
sc.createDesktopShortcut();
}
}
you can get the jar from here
Java Web Start does this. You write a regular application with a regular main method, and point to it with a short XML file with a .jnlp extension. When the user clicks the link to the XML file, Java Web Start will, among other things, create the shortcut, if your XML file contains this:
<information>
<!-- Other elements go here -->
<shortcut>
<desktop/>
</shortcut>
</information>
More details are here.
This is a fairly old topic, nevertheless I came across Austin`s brilliant answer and encountered some problems using jshortcut from within NetBeans, but I fear this might also affect Ecclipse.
s for this project. JShellLink looks at this folder on its own, so you don
t need to add the DLL`s path to any path, which could cause trouble when running on some closed-down machines.Excert form jShellLink: /** Provide access to shortcuts (shell links) from Java. * * The native library (jshortcut.dll) is loaded when JShellLink is first * loaded. * By default, JShellLink first looks for the native library in the PATH, * using System.loadLibrary. * If the native library is not found in the PATH, * JShellLink then looks through each directory in the CLASSPATH * (as determined by the value of the system property java.class.path). * If an entry in the CLASSPATH is a jar file, * then JShellLink looks for the native library * in the directory containing that jar file. * The application can override this behavior and force JShellLink to look * for the native library in a specific directory by setting the system * property JSHORTCUT_HOME to point to that directory. * This property must be set before the JShellLink class is loaded. * This makes it possible to use this library from a self-extracting jar file. */