Running an external jar file by pressing a JButton

后端 未结 1 1014
南方客
南方客 2021-01-27 22:56

I am trying to run a jar file that is in a separate directory from pressing a JButton.

I have the button and GUI setup but I cant figure out how to launch the separate j

1条回答
  •  后悔当初
    2021-01-27 23:37

    Try This

    try {
        Desktop.getDesktop().open(new File("F:\\Folder\\Folder\\folder\\yourprogram.jar"));
    } catch (IOException ex) {
        System.out.println(ex.getMessage());
    }
    

    for example open a .exe file ( Open ODBC DSN via java )

        try {
            Desktop.getDesktop().open(new File("C:\\Windows\\SysWOW64\\odbcad32.exe"));
        } catch (IOException ex) {
            try{
                Desktop.getDesktop().open(new File("C:\\Windows\\System32\\odbcad32.exe"));
            }catch(Exception exx)
            {
                System.out.println(exx.getMessage());
            }
        }
    

    0 讨论(0)
提交回复
热议问题