in tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/AbstractRunMojo.java [658:742]
protected Context createContext( Tomcat container )
throws IOException, MojoExecutionException, ServletException
{
String contextPath = getPath();
String baseDir = getDocBase().getAbsolutePath();
File overriddenContextFile = getContextFile();
StandardContext standardContext = null;
if ( overriddenContextFile != null && overriddenContextFile.exists() )
{
standardContext = parseContextFile( overriddenContextFile );
}
else if ( defaultContextFile.exists() )
{
standardContext = parseContextFile( defaultContextFile );
}
if ( standardContext != null )
{
if ( standardContext.getPath() != null )
{
contextPath = standardContext.getPath();
}
if ( standardContext.getDocBase() != null )
{
baseDir = standardContext.getDocBase();
}
}
contextPath = "/".equals( contextPath ) ? "" : contextPath;
getLog().info( "create webapp with contextPath: " + contextPath );
Context context = container.addWebapp( contextPath, baseDir );
context.setResources(
new MyDirContext( new File( project.getBuild().getOutputDirectory() ).getAbsolutePath(), //
getPath(), //
getLog() ) );
if ( useSeparateTomcatClassLoader )
{
context.setParentClassLoader( getTomcatClassLoader() );
}
enhanceContext( context );
final WebappLoader loader = createWebappLoader();
context.setLoader( loader );
if ( overriddenContextFile != null )
{
// here, send file to Tomcat for it to complain if missing
context.setConfigFile( overriddenContextFile.toURI().toURL() );
}
else if ( defaultContextFile.exists() )
{
// here, only sending default file if it indeed exists
// otherwise Tomcat will create a default context
context.setConfigFile( defaultContextFile.toURI().toURL() );
}
if ( classLoaderClass != null )
{
loader.setLoaderClass( classLoaderClass );
}
// https://issues.apache.org/jira/browse/MTOMCAT-239
// get the jar scanner to configure scanning directories as we can run a jar or a reactor project with a jar so
// the entries is a directory (target/classes)
JarScanner jarScanner = context.getJarScanner();
// normally this one only but just in case ...
if ( jarScanner instanceof StandardJarScanner )
{
( (StandardJarScanner) jarScanner ).setScanAllDirectories( jarScanAllDirectories );
}
return context;
}