1

当我使用 tomcat 7 maven 插件在 eclipse 中运行我的 web 应用程序时,我希望将一个额外的上下文部署到 tomcat。在生产环境中,此上下文使用上下文配置映射到 tomcat 目录之外的目录

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

通过这种方式可以在

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

我如何在 webapp(eclipse、tomcat7 maven 插件)的开发环境中实现相同的目标?换句话说,我希望该文件夹的内容可以通过

http://localhost:8080/userimages

或者

http://localhost:8080/myapp/userimages
4

2 回答 2

1

您应该配置 tomcat7-maven-plugin 插件。

试试这个方法:

<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>

那么你所有的网址都应该以http://www.myhost.com/ your_app_context_path /...

tomcat7:run 目标的更多可选参数可以在apache tomcat maven 插件文档中找到

于 2013-01-14T05:48:39.837 回答
0

我找到了一个不完全符合我最初想要的解决方法(使用 tomcat maven 插件发布另一个上下文),但它以某种方式解决了我的问题。我在应用程序的 webapp 文件夹中添加了一个文件夹“userimages”,并在开发时使用该文件夹。我通过在 pom.xml 中使用具有以下配置的“maven-war-plugin”来防止此文件夹进入战争并因此进入生产服务器

 <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>

也在这里这里检查

于 2012-08-31T09:30:59.373 回答