Question

When I run my web app inside eclipse using tomcat 7 maven plugin, I want an additional context to be deployed to tomcat. On the production enviroment this context is mapped to a directory outside tomcat dir using a context configuration

 <Context path="/userimages" docBase="C:/test/userimages">
 </Context>

And by this way is available in

http://wwww.myhost.com/userimages/test.jpg

How I achive the same on the development enviroment of the webapp (eclipse, tomcat7 maven plugin)? In other words I want the contents of that folder to be accessible through

http://localhost:8080/userimages

or

http://localhost:8080/myapp/userimages
Was it helpful?

Solution 2

I found a workaround that doesn't do exactly what I originally wanted (publish another context using the tomcat maven plugin) but it solves my problem in a way. I add a folder "userimages" in the webapp folder of the application and this folder is used when developing. I prevent this folder from getting in the war and thus in the production server by using the "maven-war-plugin" with the following configuration in the pom.xml

 <build>
  ....
  <plugins>
   ....
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.2</version>
        <configuration>
            <packagingExcludes>userimages/</packagingExcludes>
        </configuration>
    </plugin>
    ....
  </plugins>
  ....
 </build>

Check also here and here

OTHER TIPS

You should configure tomcat7-maven-plugin plugin.

Try this way:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.0</version>
    <configuration>
        <path>your_app_context_path</path>
        <uriEncoding>utf-8</uriEncoding>
    </configuration>
</plugin>

Then all your urls should start with http://wwww.myhost.com/your_app_context_path/...

More optional parameters for tomcat7:run goal can be found at apache tomcat maven plugin document

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top