Running an external jar file by pressing a JButton

删除回忆录丶 提交于 2019-12-02 14:54:54

问题


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 jar file.

What do I put in this code block

private void jButton1MouseReleased(java.awt.event.MouseEvent evt) {                                       

}     

回答1:


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());
        }
    }


来源:https://stackoverflow.com/questions/14988741/running-an-external-jar-file-by-pressing-a-jbutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!