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.
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.
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?
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.
Thank you in advance
EDIT: As you asked for, i'm adding the code of what i've tried:
this is the project structure
project
├───src
│ ├───main
│ │ └───java
│ │ ├───model <--- where my class is
│ │ ├───controllers
│ │ ├───utilities
│ │ └───views
│ ├───resources <--- this is where is (formerly) accessed the content i need
| | ├─── jarfile.jar <--- i've placed file here and included to build path
│ │ └───-various folders and files -
│ └───test
└───target
inside the jar file there are the packages src.resources.blalblaba and inside of this, the folder i need
Way1:
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"
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
}
Way 2: paths used "folderINeed","src/resources/blablabla/folderINeed","blablabla/folderINeed","../../../resources/blablabla/folderINeed" <--- URL return null but, at least, doesn't raise a NullPointerException.
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();
}
}
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 here