I need to access some resources (for a contextual help system) which may be located either in a directory tree (somewhere in the filesystem) or contained into a specific .jar.
Resources in the filesystem should take precedence over "packed" ones.
I should provide a runtime (not a compile-time action) command to migrate all resources from filesytem directory tree to the .jar package.
I want to build a separate .jar to contain just those resources. I don't want/need to modify code. I need to deliver a product with minimal help and allow the costomer to refine it and update need to recompile. Customer will then distribute the "improved" version.
What is the best way to implement this?
I'm interested specifically in the "migration" part, since I should be able to code the resource access part, but comments are always welcome.
There are various ways this can be implemented but re-using Java's ability to read resources from a directory on the classpath looks the easiest to me.
Deliver the application with a zip-file containing the updatable help-resources. At application start, extract this zip-file to apphome/help-resources
but do not overwrite newer/modified files. Use the technique in this answer to add the apphome/help-resources
directory to the class-path. From then on resources can be loaded as if they are in a jar-file on the classpath (no special code needed).
The customer can update the files in apphome/help-resources
and using a runtime-command the zip-file can be updated/recreated with the files in the apphome/help-resources
directory. Or if the customer has 7-zip or something similar, just create the zip-file using the zip-tool.