简体   繁体   English

包括runnable jar文件中的源文件

[英]including source files in runnable jar file

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. 我必须使用runnable jar文件创建安装程序,当jar文件运行时,它必须复制某些目录上的文件。 I have included few folders in the java project as in the below image : 我在java项目中包含了一些文件夹,如下图所示: 在此输入图像描述

I have to paste dcc, contactless and vfsc5000 folder on to certain directories. 我必须将dcc,contactless和vfsc5000文件夹粘贴到某些目录。

I am using this piece of code : 我正在使用这段代码:

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

  }
}

But when I export runnable jar and execute it in the cmd, it throws File not found exception, Source "resources does not exist". 但是当我导出runnable jar并在cmd中执行它时,它会抛出File not found异常,Source“资源不存在”。 It means the jar is not exporting those folders. 这意味着jar不会导出这些文件夹。 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 单击项目 - >属性 - >构建路径 - >源 - >添加文件夹

and then use class.getResourceAsStream() to read it instead of File and FileReader. 然后使用class.getResourceAsStream()来读取它而不是File和FileReader。

Hope it works !! 希望它有效!! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM