private static List < URL > getBundleEmbeddedLibs ( final URL jarFileUrl ) throws IOException , PrivilegedActionException { return AccessController . doPrivileged ( new PrivilegedExceptionAction < List < URL > > ( ) { public List < URL > run ( ) throws Exception { JarFile jarFile = new JarFile ( URLDecoder . decode ( jarFileUrl . getFile ( ) , "utf-8" ) ) ; List < URL > libs = new LinkedList < URL > ( ) ; Attributes manifest = jarFile . getManifest ( ) . getMainAttributes ( ) ; String rawBundleClasspath = manifest . getValue ( "Bundle-ClassPath" ) ; if ( rawBundleClasspath != null ) { Set < String > allValidBundleClassPaths = new HashSet < String > ( ) ; String [ ] bundleClassPaths = rawBundleClasspath . split ( "," ) ; for ( String bundleClassPath : bundleClassPaths ) { bundleClassPath = bundleClassPath . trim ( ) ; if ( ! bundleClassPath . equals ( "." ) && bundleClassPath . endsWith ( ".jar" ) ) { allValidBundleClassPaths . add ( bundleClassPath ) ; } } Enumeration < JarEntry > entries = jarFile . entries ( ) ; File tempDir = createTempDir ( "was-cmdline" ) ; tempDir . deleteOnExit ( ) ; int MAX_READ_SIZE = 512 ; int offset = 0 , read = 0 ; byte [ ] buff = new byte [ MAX_READ_SIZE ] ; while ( entries . hasMoreElements ( ) ) { JarEntry jarEntry = entries . nextElement ( ) ; String entryName = jarEntry . getName ( ) ; if ( allValidBundleClassPaths . contains ( entryName ) ) { String fileName = entryName ; int index ; while ( ( index = fileName . indexOf ( "/" ) ) != - 1 ) { fileName = fileName . substring ( index + 1 ) ; } InputStream stream = jarFile . getInputStream ( jarEntry ) ; File file = new File ( tempDir , fileName ) ; file . deleteOnExit ( ) ; FileOutputStream fileStream = new FileOutputStream ( file ) ; while ( ( read = stream . read ( buff , offset , MAX_READ_SIZE ) ) > 0 ) { fileStream . write ( buff , 0 , read ) ; } fileStream . flush ( ) ; fileStream . close ( ) ; stream . close ( ) ; libs . add ( file . toURI ( ) . toURL ( ) ) ; } } } jarFile . close ( ) ; return libs ; } } ) ; }
Support for embedded libs in a bundle .