1

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 : enter image description here

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

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". It means the jar is not exporting those folders. Please help me solve this .Thanks.

Talib
  • 1,134
  • 5
  • 31
  • 58
  • Have you thought of using Windows installer, or instashield etc? They are better suited for these kind of tasks, and will be more manageable in the long term. – Pradeep Pati Jul 31 '16 at 15:48
  • 1
    you can use ant to build a runnable jar file like [here](http://stackoverflow.com/questions/9874550/how-to-create-a-bundled-runnable-jar-using-ant) and [here](https://ideoplex.com/2008/10/05/building-an-executable-jar-with-ant/) – guleryuz Jul 31 '16 at 16:03
  • Are you planning to run this .jar on other computers? – VGR Jul 31 '16 at 17:38
  • @VGR yes i will use this to install on other computers and can use windows installer for this. – Talib Jul 31 '16 at 18:42
  • @PradeepPati my requirement is a jar file and i have to use it for a remote installation. – Talib Jul 31 '16 at 19:00
  • 1
    Unless you plan to require that every user keeps a copy of your Eclipse project on their computer, you will need to embed all of those files inside the .jar. Which means they will not be accessible as regular files anymore; they will be [resources](http://stackoverflow.com/documentation/java/2433/resources-on-classpath#t=20160731193155774408&a=remarks). – VGR Jul 31 '16 at 19:32
  • 1
    @VGR yes thats what am trying to achieve. can you help about this ? – Talib Aug 01 '16 at 05:34

1 Answers1

1

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.

Hope it works !! :)

techprat
  • 375
  • 7
  • 23