Zkejid
Zkejid

Reputation: 81

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

My goal is to deploy several webapps using tomcat-maven-plugin and make some cross context interactions between them. This is for prototyping purposes. So I created two war modules (core & webapp1), placed apropriate context.xml into META-INF folder of both of them and configured tomcat7 plugin. But webapps were deployed with default context configuration. When deployed into common Tomcat 7 container, it all works perfect - I can access context of another webbapp.

My question is what am I doing wrong? Or maybe this is restriction of embedded tomcat (though I found nothing about difference)?

Here is my context.xml:

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

Configuration of tomcat plugin (I wonder if it is important, 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 code of core 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);

Upvotes: 3

Views: 652

Answers (0)

Related Questions