按JButton运行外部jar文件 [英] Running an external jar file by pressing a JButton

查看:125
本文介绍了按JButton运行外部jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个jar文件,该文件位于与按JButton不同的目录中。

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

我有按钮和GUI设置,但我无法弄清楚如何启动单独的jar文件。

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

}     


推荐答案

试试这个

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

例如打开.exe文件(通过java打开ODBC DSN)

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

这篇关于按JButton运行外部jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆