private WebAppContext createdWebAppContext ( ) throws Exception { final String path = configuration . getPath ( ) ; final String webapp = configuration . getWebapp ( ) ; final String classpath = configuration . getClasspath ( ) ; final ClassLoader parentClassLoader = configuration . getParentClassLoader ( ) ; final String overrideDescriptor = configuration . getOverrideDescriptor ( ) ; final Resource baseResource = configuration . getBaseResource ( ) ; final String containerJarPattern = configuration . getContainerJarPattern ( ) ; final String webInfJarPattern = configuration . getWebInfJarPattern ( ) ; WebAppContext ctx = new WebAppContext ( ) ; if ( containerJarPattern != null ) { ctx . setAttribute ( WebInfConfiguration . CONTAINER_JAR_PATTERN , containerJarPattern ) ; } else if ( JavaUtils . isPostJdk9 ( ) ) { // Fix to make TLD scanning works with Java >= 9 ctx . setAttribute ( WebInfConfiguration . CONTAINER_JAR_PATTERN , ".*\\.jar" ) ; } if ( webInfJarPattern != null ) { ctx . setAttribute ( WebInfConfiguration . WEBINF_JAR_PATTERN , webInfJarPattern ) ; } final ClassLoader systemClassLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; final ClassLoader classLoader ; if ( parentClassLoader != null ) { classLoader = new CompositeClassLoader ( parentClassLoader , systemClassLoader ) ; } else { classLoader = systemClassLoader ; } ctx . setClassLoader ( classLoader ) ; ctx . setContextPath ( path ) ; if ( baseResource == null ) { // use default base resource ctx . setBaseResource ( newResource ( webapp ) ) ; } else { ctx . setBaseResource ( baseResource ) ; } if ( overrideDescriptor != null ) { ctx . setOverrideDescriptor ( overrideDescriptor ) ; } ctx . setConfigurations ( new Configuration [ ] { new WebInfConfiguration ( ) , new WebXmlConfiguration ( ) , new AnnotationConfiguration ( ) , new JettyWebXmlConfiguration ( ) , new MetaInfConfiguration ( ) , new FragmentConfiguration ( ) } ) ; if ( isNotBlank ( classpath ) ) { // Fix to scan Spring WebApplicationInitializer // This will add compiled classes to jetty classpath // See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration // And more precisely: http://stackoverflow.com/a/18449506/1215828 File classes = new File ( classpath ) ; PathResource containerResources = new PathResource ( classes . toURI ( ) ) ; ctx . getMetaData ( ) . addContainerResource ( containerResources ) ; } ctx . setParentLoaderPriority ( true ) ; ctx . setWar ( webapp ) ; ctx . setServer ( server ) ; // Add server context server . setHandler ( ctx ) ; return ctx ; }
Build web app context used to launch server . May be override by subclasses .