protected URL getResourceURL ( File file , String resourceName ) { try { JarFile jarFile = ( JarFile ) jarFiles . get ( file ) ; if ( jarFile == null && file . isDirectory ( ) ) { File resource = new File ( file , resourceName ) ; if ( resource . exists ( ) ) { try { return FILE_UTILS . getFileURL ( resource ) ; } catch ( MalformedURLException ex ) { return null ; } } } else { if ( jarFile == null ) { if ( file . exists ( ) ) { jarFile = new JarFile ( file ) ; jarFiles . put ( file , jarFile ) ; } else { return null ; } // potential race-condition jarFile = ( JarFile ) jarFiles . get ( file ) ; } JarEntry entry = jarFile . getJarEntry ( resourceName ) ; if ( entry != null ) { try { return new URL ( "jar:" + FILE_UTILS . getFileURL ( file ) + "!/" + entry ) ; } catch ( MalformedURLException ex ) { return null ; } } } } catch ( Exception e ) { String msg = "Unable to obtain resource from " + file + ": " ; log ( msg + e , Project . MSG_WARN ) ; System . err . println ( msg ) ; e . printStackTrace ( ) ; } return null ; }
Returns the URL of a given resource in the given file which may either be a directory or a zip file .