Это решение будет копировать файл JAR, а также содержимое внутри файла JAR.
public void copyResourcesRecursively(URL originUrl, File destination) throws Exception {
URLConnection urlConnection = originUrl.openConnection();
if (urlConnection instanceof JarURLConnection) {
copyJarResourcesRecursively(destination, (JarURLConnection) urlConnection);
} else if (urlConnection instanceof FileURLConnection) {
FileUtils.copyFilesRecusively(new File(originUrl.getPath()), destination);
} else {
throw new Exception("URLConnection[" + urlConnection.getClass().getSimpleName() +
"] is not a recognized/implemented connection type.");
}
}
public void copyJarResourcesRecursively(File destination, JarURLConnection jarConnection ) throws IOException {
JarFile jarFile = jarConnection.getJarFile();
for (JarEntry entry : CollectionUtils.iterable(jarFile.entries())) {
if (entry.getName().startsWith(jarConnection.getEntryName())) {
String fileName = StringUtils.removeStart(entry.getName(), jarConnection.getEntryName());
if (!entry.isDirectory()) {
InputStream entryInputStream = null;
try {
entryInputStream = jarFile.getInputStream(entry);
FileUtils.copyStream(entryInputStream, new File(destination, fileName));
} finally {
FileUtils.safeClose(entryInputStream);
}
} else {
FileUtils.ensureDirectoryExists(new File(destination, fileName));
}
}
}
}
См. Здесь