private String extractClassPathResourceToTempLocation(final String hostPath) {
File tmpLocation = createTempDirectory();
tmpLocation.delete();
String urldecodedJarPath = unencodeResourceURIToFilePath(hostPath);
String internalPath = hostPath.replaceAll("[^!]*!/", "");
try (JarFile jarFile = new JarFile(urldecodedJarPath)) {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
final String name = entry.getName();
if (name.startsWith(internalPath)) {
log.debug("Copying classpath resource(s) from {} to {} to permit Docker to bind", hostPath, tmpLocation);
copyFromJarToLocation(jarFile, entry, internalPath, tmpLocation);
}
}
} catch (IOException e) {
throw new IllegalStateException("Failed to process JAR file when extracting classpath resource: " + hostPath, e);
}
deleteOnExit(tmpLocation.toPath());
return tmpLocation.getAbsolutePath();
}