包括runnable jar文件中的源文件 [英] including source files in runnable jar file

查看:116
本文介绍了包括runnable jar文件中的源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须用runnable jar文件创建安装程序,当jar文件运行时,它必须复制某些目录上的文件。我在java项目中包含了一些文件夹,如下图所示:

I have to create the installer with runnable jar file ,when the jar file will run it has to copy the files on some directories. I have included few folders in the java project as in the below image :

我必须粘贴dcc,非接触式和vfsc5000文件夹到某些目录。

I have to paste dcc, contactless and vfsc5000 folder on to certain directories.

我正在使用这段代码:

public class copyFiles {
  // private static final String MAIN_PATH = "C:\\Users\\Hamza\\Documents\\";
  private static final String MAIN_PATH = "resources";

  public static void main(String[] args) throws IOException {
    // file1: "Hello World!"
    FileUtils.copyDirectory(FileUtils.getFile(MAIN_PATH), // source
        FileUtils.getFile("C:\\Windows\\java\\classes\\postilion" + "contactlessVfsc5000\\")); // destination

  }
}

但是当我输出runnable jar并在cmd中执行它,它抛出File not found异常,Source资源不存在。这意味着jar不会导出这些文件夹。
请帮我解决这个问题。谢谢。

But when I export runnable jar and execute it in the cmd, it throws File not found exception, Source "resources does not exist". It means the jar is not exporting those folders. Please help me solve this .Thanks.

推荐答案

你必须使用以下内容将所需的文件夹添加到构建路径步骤:

you have to add the required folder to the build path using following step:

点击项目 - >属性 - >构建路径 - >源 - >添加文件夹

click project -> properties -> Build Path -> Source -> Add Folder

然后使用class.getResourceAsStream()来读取它而不是File和FileReader。

and then use class.getResourceAsStream() to read it instead of File and FileReader.

希望它有效!! :)

这篇关于包括runnable jar文件中的源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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