0

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) {                                       

}     
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417

1 Answers1

4

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());
        }
    }
Azad
  • 5,047
  • 20
  • 38
  • 1
    Better to check if the machine has a Java installed (via System environment variables maybe?). Also, consider to use `/` instead of \\ as `/` is OS-independent. +1 for you :) – Eng.Fouad Feb 20 '13 at 20:03