protected void setupForWar ( ) { // Identify the war file that contains this class ProtectionDomain protectionDomain = RunWar . class . getProtectionDomain ( ) ; URL location = protectionDomain . getCodeSource ( ) . getLocation ( ) ; String warFilePath = trimToFile ( location . toExternalForm ( ) ) ; File warFile = new File ( warFilePath ) ; if ( ! warFile . exists ( ) ) { throw new IllegalStateException ( "war file not found: " + warFilePath ) ; } webapp . setWar ( warFilePath ) ; webapp . setClassLoader ( Thread . currentThread ( ) . getContextClassLoader ( ) ) ; if ( ! Boolean . getBoolean ( "webapp.extractWar" ) ) { try { webapp . setExtractWAR ( false ) ; webapp . setBaseResource ( JarResource . newJarResource ( Resource . newResource ( warFile ) ) ) ; } catch ( IOException e ) { throw new RuntimeException ( "Error setting base resource to:" + warFilePath , e ) ; } } if ( log ( ) . isDebugEnabled ( ) ) { ClassLoader classLoader = webapp . getClassLoader ( ) ; log ( ) . debug ( "webapp classLoader: " + classLoader ) ; if ( classLoader instanceof URLClassLoader ) { URL [ ] urls = ( ( URLClassLoader ) classLoader ) . getURLs ( ) ; log ( ) . debug ( "webapp classLoader URLs: " + Arrays . toString ( urls ) ) ; } } }
Setup the webapp pointing to the war file that contains this class .