How to create shortcut icon for java program

前端 未结 11 2533
野性不改
野性不改 2020-12-29 10:57

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

相关标签:
11条回答
  • 2020-12-29 10:58

    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

    0 讨论(0)
  • 2020-12-29 11:04

    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();
        }
    
    }
    
    0 讨论(0)
  • 2020-12-29 11:05

    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.

    0 讨论(0)
    1. right click on desktop select option new - shortcut
    2. click on brows button and select path of jar file
    3. select next - finish button.
    4. shortcut file is created on desktop . right click on shortcut file
    5. select properties
    6. click on change icon and change icon of file

    Congratulations you created a shortcut

    0 讨论(0)
  • 2020-12-29 11:06

    Creating shortcut for java .class file is very easy, just follow the instructions:

    1. create a .class file using javac
    2. 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

    0 讨论(0)
  • 2020-12-29 11:06

    To do this:

    • Right click in the destination folder(for the shortcut)
    • Click New -> Shortcut
    • In "Type the location of the item" enter java -jaryour jar path(full)
    • Click next end enter a name
    • It should now work!

    You can change the icon of your shortcut, too:

    • Right click -> Properties -> Shortcut -> Change Icon
    0 讨论(0)
提交回复
热议问题