如何在可执行jar中打开帮助文件 [英] how to open help file in executable jar

查看:132
本文介绍了如何在可执行jar中打开帮助文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击帮助按钮时,我想打开.chm帮助文件.当我在日食时做得很好.但是,当我创建可执行jar文件时,其给出的错误是无法打开文件". 这是我的代码:

I want to open .chm help file when click on Help button. When i do it in eclipse its working good. but when i create executable jar file then its giving error that "can not open file". this is my code:

String path = Toolkit.getDefaultToolkit().getClass().getResource("/resources/UserAccountHelpNew.chm").getPath();

    String path1 = path.substring(1);
    System.out.println(path1);

    try {
        Process process = Runtime.getRuntime().exec("hh.exe "+path1);
        process.waitFor();
    } catch (InterruptedException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }

推荐答案

hh.exe无法在jar中打开文件.您需要编写一些代码,将Toolkit.getDefaultToolkit().getClass().getResource("/resources/UserAcountHelpNew.chm")的内容复制到文件系统上的某个位置,或者将此文件与可执行jar一起分发.

hh.exe can't open files in a jar. You need to either write some code copy the contents of Toolkit.getDefaultToolkit().getClass().getResource("/resources/UserAcountHelpNew.chm") to a place on the file system, or distribute this file alongside the executable jar.

它在Eclipse中工作的原因是因为您可能在文件系统上有该文件.当您的工作目录更改时,hh.exe不再可以找到该文件.

The reason it works in Eclipse is because you probably have the file on the file system. When your working directory changes, hh.exe can no longer find the file.

这篇关于如何在可执行jar中打开帮助文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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