static void copyJarResourceToPath ( JarURLConnection jarConnection , File destPath ) { try ( JarFile jarFile = jarConnection . getJarFile ( ) ) { String jarConnectionEntryName = jarConnection . getEntryName ( ) ; if ( ! jarConnectionEntryName . endsWith ( "/" ) ) { jarConnectionEntryName += "/" ; } /** * Iterate all entries in the jar file. */ for ( Enumeration < JarEntry > e = jarFile . entries ( ) ; e . hasMoreElements ( ) ; ) { JarEntry jarEntry = e . nextElement ( ) ; String jarEntryName = jarEntry . getName ( ) ; /** * Extract files only if they match the path. */ if ( jarEntryName . startsWith ( jarConnectionEntryName ) ) { String filename = jarEntryName . substring ( jarConnectionEntryName . length ( ) ) ; File targetFile = new File ( destPath , filename ) ; if ( jarEntry . isDirectory ( ) ) { targetFile . mkdirs ( ) ; } else { if ( ! targetFile . exists ( ) || targetFile . length ( ) != jarEntry . getSize ( ) ) { try ( InputStream is = jarFile . getInputStream ( jarEntry ) ; OutputStream out = FileUtils . openOutputStream ( targetFile ) ) { IOUtils . copy ( is , out ) ; } } } } } } catch ( IOException e ) { logger . warn ( e . getMessage ( ) , e ) ; } }
Copies resources from the jar file of the current thread and extract it to the destination path .