private ClassLoader createClassLoader ( File warFile , File tempDirectory ) { try { File condiLibDirectory = new File ( tempDirectory , "condi" ) ; condiLibDirectory . mkdirs ( ) ; File jettyWebappDirectory = new File ( tempDirectory , "webapp" ) ; jettyWebappDirectory . mkdirs ( ) ; List < URL > urls = new ArrayList <> ( ) ; JarInputStream in = new JarInputStream ( new FileInputStream ( warFile ) ) ; while ( true ) { JarEntry entry = in . getNextJarEntry ( ) ; if ( entry == null ) { break ; } String name = entry . getName ( ) ; String prefix = "META-INF/jettyconsole/lib/" ; if ( ! entry . isDirectory ( ) ) { if ( name . startsWith ( prefix ) ) { String simpleName = name . substring ( name . lastIndexOf ( "/" ) + 1 ) ; File file = new File ( condiLibDirectory , simpleName ) ; unpackFile ( in , file ) ; urls . add ( file . toURI ( ) . toURL ( ) ) ; } else if ( ! name . startsWith ( "META-INF/jettyconsole" ) && ! name . contains ( "JettyConsoleBootstrapMainClass" ) ) { File file = new File ( jettyWebappDirectory , name ) ; file . getParentFile ( ) . mkdirs ( ) ; unpackFile ( in , file ) ; } } } in . close ( ) ; return new URLClassLoader ( urls . toArray ( new URL [ urls . size ( ) ] ) , JettyConsoleBootstrapMainClass . class . getClassLoader ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } }
Create a URL class loader containing all jar files in the given directory