How to apply context configuration in tomcat-maven-plugin?

My goal is to deploy multiple webapps with tomcat-maven-plugin and do some cross-context interactions between them. This is for prototyping purposes. So I created two military modules (core and webapp1), placed apro with the appropriate context.xml in the META-INF folder of both of them, and configured the tomcat7 plugin. But webapps were deployed with default context setting. When deployed to a shared Tomcat 7 container, everything works fine - I can access the context of another webbapp.

My question is, what am I doing wrong? Or maybe it's an embedded tomcat limitation (although I haven't found anything about the difference)?

Here is my context.xml:

<Context crossContext="true">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

      

Tomcat plugin config (I wonder if it matters, but who knows):

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.0</version>
    <configuration>
        <path>/</path>
        <port>8080</port>
        <addContextWarDependencies>true</addContextWarDependencies>
        <addWarDependenciesInClassloader>true</addWarDependenciesInClassloader>        <warSourceDirectory>${project.build.directory}/${project.build.finalName}/</warSourceDirectory>
        <webapps>
            <webapp>
                <groupId>lfcms-several-webapps-proto</groupId>
                <artifactId>webapp1</artifactId>
                <version>1.0-SNAPSHOT</version>
                <type>war</type>
                <asWebapp>true</asWebapp>
            </webapp>
            <webapp>
                <groupId>lfcms-several-webapps-proto</groupId>
                <artifactId>webapp2</artifactId>
                <version>1.0-SNAPSHOT</version>
                <type>war</type>
                <asWebapp>true</asWebapp>
            </webapp>
        </webapps>
    </configuration>
</plugin>

      

Here is the code for the main servlet:

final ServletContext additionalContext = ctx.getContext("/webapp1");
if (additionalContext == null) throw new ServletException("can't get context of /webapp1");
final RequestDispatcher disp = additionalContext.getRequestDispatcher("/webapp1");
disp.include(req, resp);

      

+3


source to share





All Articles