private void extractJar ( JarFile jarFile , File dstDir ) throws DeploymentException { // Extract jar contents to a classpath location JarInputStream jarIs = null ; try { jarIs = new JarInputStream ( new BufferedInputStream ( new FileInputStream ( jarFile . getName ( ) ) ) ) ; for ( JarEntry entry = jarIs . getNextJarEntry ( ) ; jarIs . available ( ) > 0 && entry != null ; entry = jarIs . getNextJarEntry ( ) ) { logger . trace ( "jar entry = " + entry . getName ( ) ) ; if ( entry . isDirectory ( ) ) { // Create jar directories. File dir = new File ( dstDir , entry . getName ( ) ) ; if ( ! dir . exists ( ) ) { if ( ! dir . mkdirs ( ) ) { logger . debug ( "Failed to create directory " + dir . getAbsolutePath ( ) ) ; throw new IOException ( "Failed to create directory " + dir . getAbsolutePath ( ) ) ; } } else logger . trace ( "Created directory" + dir . getAbsolutePath ( ) ) ; } else // unzip files { File file = new File ( dstDir , entry . getName ( ) ) ; File dir = file . getParentFile ( ) ; if ( ! dir . exists ( ) ) { if ( ! dir . mkdirs ( ) ) { logger . debug ( "Failed to create directory " + dir . getAbsolutePath ( ) ) ; throw new IOException ( "Failed to create directory " + dir . getAbsolutePath ( ) ) ; } else logger . trace ( "Created directory" + dir . getAbsolutePath ( ) ) ; } pipeStream ( jarFile . getInputStream ( entry ) , new FileOutputStream ( file ) ) ; } } } catch ( Exception e ) { throw new DeploymentException ( "failed to extract jar file " + jarFile . getName ( ) ) ; } finally { if ( jarIs != null ) { try { jarIs . close ( ) ; } catch ( IOException e ) { logger . error ( "failed to close jar input stream" , e ) ; } } } }
This method will extract all the files in the jar file