Solved, see my post below
I want to copy files from one .jar to another using java. But not all files of the jar shall be copied. I only want one specific folder to be copied which also can contain subfolders. I already have the code to copy files from one jar to another:
public static void copyFiles(final File file) throws IOException {
final JarFile targetJar = new JarFile(file);
final JarOutputStream output = new JarOutputStream(new FileOutputStream(file));
final JarFile localJar = new JarFile(new File(JarEditor.class.getProtectionDomain().getCodeSource().getLocation().getFile()));
// WRAPPER_CONTENT is a String[] which contains all names of the files i want to copy
for (final String entryName : StringResource.WRAPPER_CONTENT) {
final JarEntry entryToCopy = localJar.getJarEntry(entryName);
final JarEntry targetEntry = new JarEntry(entryName);
output.putNextEntry(targetEntry);
final InputStream input = localJar.getInputStream(entryToCopy);
final byte[] buffer = new byte[10240];
int readByte = 0;
while ((readByte = input.read(buffer)) >= 0) {
output.write(buffer, 0, readByte);
}
}
output.flush();
output.close();
localJar.close();
targetJar.close();
}
Currently im copying the files by running through a hardcoded list of their names. But id prefer a more flexible way so i could add and remove resources from my jar and it still will work. They all have the same parent-folder in the jar. So how would i go through that one folder and only copy those files?
Also maybe worth mentioning, all files which shall be copied are located in the jarfile my runtime is coming from as you probably got from looking at my code.
Thanks for help
Baschdi