Hi I have created executable jar of my java program i want to create shortcut icon for that jar. Means may be my jar is in any other memory location of hard drive(eg- D or E
You need to look around for Java Windows Installers, they have functionality to create desktop shortcuts. Take a look at this article and this one too.
Install4J is my personal favorite
There is a JNI library named jshortcut-0.4-oberzalek.jar ,you can download it from this link just given below and add to your project libraries.
https://github.com/jimmc/jshortcut/downloads
It works unbelievably perfect in my project.Here I use an additional function named getdir(),to get current location of your deployed project folder, and store value in a variable named 'PRJT_PTH'.
After that your deployed project can save on any drive,no matter where it is.It will automatically creates a shortcut on desktop
Here is the code that I used for creating a shortcut to deployed project.(JMM.jar in my case)
import net.jimmc.jshortcut.JShellLink;
String PRJT_PATH="";
private void getdir() throws IOException{
File f=new File(".");
File[] f1=f.listFiles();
PRJT_PATH=f.getCanonicalPath();
} //you can call this function at windowOpened event,this will get path of current directory where your project located.
JShellLink link;
String filePath;
public void createDesktopShortcut() { //after that call createDesktopShortcut() function to create shortcut to desktop.
try {
link = new JShellLink();
filePath = JShellLink.getDirectory("") + PRJT_PTH +"\\JMM.jar";
} catch (Exception e) {
}
try {
link.setFolder(JShellLink.getDirectory("desktop"));
link.setName("JMM"); //Choose a name for your shortcut.In my case its JMM.
link.setPath(filePath); //link for our executable jar file
link.setIconLocation(PRJT_PATH1+ "\\jmm.ico"); //set icon image(before that choose your on manual icon file inside our project folder.[jmm.ico in my case])
link.save();
} catch (Exception ex) {
ex.getmessage();
}
}
Assume your jar file is in location c:\pgm\abc.jar
open notepad and type c: cd\ cd pgm java -jar abc.jar
Then save that notepad document as "anyname.bat"
Then create a shortcut for that batch file (ie...right click that file and click "Create Shortcut"). You can use this shortcut to run your jar file.
Congratulations you created a shortcut
Creating shortcut for java .class file is very easy, just follow the instructions:
open a notepad and type following line (note: here filename is the name of my file. Type your file name without .java or .class )
java filename
pause
3.save it as anyname.bat in the same folder where your .class file resides 4.copy and paste shortcut of your new file
New -> Shortcut
java -jar
your jar path(full)