title: Best practices for including large resource folder into java project
body: <p>I'm working on a project where having access to a big resource folder (structure with thousand of little images) is required. The client want to offer the app through a native installation (which includes the JVM that the app require to run). He doesn't want to pack that resources as a folder in the app because it would create a folder structure as big as the original in the final user's hard drive (the folder doesn't take much space but it has many little files), plus the folder could be stealed easily by simply copying it. Giving this, I can't package all the app with a resource folder in a jar file, as far as i know jar files are not installables. Another requirement is that client needs certain flexibility to add some files in a installed app folders structure to add new features to the program. So an installation is the only way (i think) to obtain this.</p>
  
  <p>I've tried to pack them in a jar file, include it in the build path and tried to access it but i failed even with all the research i've made through various sites.  Tried getResources() in a million ways but it was impossible to get a simple directory inside the jar file meanwhile doing it from a folder outside the jar is really easy. I need to get access to a directory in order to get a list of files it cointains.</p>
  
  <p>Arrived to this point. I've started to ask myself if i'm facing this problem on the best way so i wanted to ask you all: how would you package the resources you need in a native java app with this requirements?</p>
  
  <p>I'm even thinking about create some kind of encryption proccess to create a single file with all the information and simply temporarily decrypt it when needed at runtime but i think there would be a simpler and cleaner way to face this.</p>
  
  <p>Thank you in advance</p>
  
  <p><strong>EDIT:</strong> As you asked for, i'm adding the code of what i've tried:</p>
  
  <p>this is the project structure</p>
  
  <pre><code>project
  ├───src
  │   ├───main
  │   │   └───java
  │   │       ├───model &lt;--- where my class is
  │   │       ├───controllers
  │   │       ├───utilities
  │   │       └───views
  │   ├───resources &lt;--- this is where is (formerly) accessed the content i need
  |   |   ├─── jarfile.jar &lt;--- i've placed file here and included to build path
  │   │   └───-various folders and files -
  │   └───test
  └───target
  </code></pre>
  
  <p>inside the jar file there are the packages src.resources.blalblaba and inside of this, the folder i need</p>
  
  <p>Way1: </p>
  
  <p>getResources replacing jar file "." with "/" tried with paths: "src/resources/blablabla/folderINeed","src/resources/src/resources/blablabla" (due to possible duplicity), "folderINeed", "blablabla/folderINeed"  -> URI always get NullPointerException with message "null"</p>
  
  <pre><code>public void loadContent(String contentPath) throws Exception
  { 
      File resources= null;
      File[] listFiles = null;
  
      URI uri = getClass().getClassLoader().getResource(contentPath).toURI();
      resources= new File(uri);
      listFiles = resources.listFiles();
  
      //do some file proccessing and load them
  }
  </code></pre>
  
  <p>Way 2: paths used "folderINeed","src/resources/blablabla/folderINeed","blablabla/folderINeed","../../../resources/blablabla/folderINeed" &lt;--- URL return null but, at least, doesn't raise a NullPointerException.</p>
  
  <pre><code>public void loadContent(String contentPath) throws Exception
  { 
      // conseguimos todas las carpetas de animaciones
      File resources;
      File[] listFiles = null;
  
      URL url = MyClass.class.getResource(contentPath);
      if (url == null) {
           // error - missing folder
      } else {
          resources = new File(url.toURI());
          listFiles = resources.listFiles();
      }
  }
  </code></pre>
  
  <p>Way 3: some complex code using class JarFile that didn't work for me and was oriented to get a simple file, not a folder. Obtained <a href="https://stackoverflow.com/questions/11012819/how-can-i-get-a-resource-folder-from-inside-my-jar-file" title="here">here</a></p>