【发布时间】:2013-06-14 16:02:32
【问题描述】:
原帖:
我想过滤在 Jetty 8.1 servlet 容器上运行的 Java 6 Web 应用程序的 web.xml 部署描述符,但到目前为止它不起作用。我想根据活动的 Maven 配置文件设置不同的 JSF 项目阶段:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>${jsfProjectStage}</param-value>
</context-param>
pom.xml 中的配置文件部分如下所示:
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<jsfProjectStage>Development</jsfProjectStage>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<jsfProjectStage>Production</jsfProjectStage>
</properties>
</profile>
</profiles>
在互联网上,您可以找到几种方法来实现这一点,例如使用替代的 web.xml 文件。但对我来说,最明显的方式似乎是使用 maven-war-plugin:
<build>
<finalName>...</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webResources>
<webResource>
<directory>src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
<includes>
<include>web.xml</include>
</includes>
</webResource>
</webResources>
</configuration>
</plugin>
...
</plugins>
</build>
由于您找到了许多使用此代码 sn-p 的答案或文章,我想知道为什么它对我不起作用。我尝试将<webResource> 替换为<resource>(经常以这种方式找到),我还尝试添加<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>,但没有任何效果。
有没有人知道,为了正确过滤 web.xml,这里缺少什么?还是我必须明确指定<filters>?
谢谢
塞巴斯蒂安
更新:
感谢user944849我现在知道我没有过滤web.xml的原因不是maven-war-plugin而是jetty-maven-plugin,因为我使用mvn jetty:run来运行(未组装) 网络应用程序。有谁知道在运行未组装的 webapp 之前如何使用 jetty-maven-plugin 过滤web.xml?
【问题讨论】:
-
你的maven命令是什么?特别是,您如何激活配置文件?
<activeByDefault>表示“只有在没有其他配置文件处于活动状态时才处于活动状态。” -
我在 Eclipse 中使用 Maven,并且我的 Run Configuration 的 Goals 用于开发构建设置为
clean jetty:run,没有明确的 配置文件设置。生产版本的目标设置为clean install,Profiles 设置为production。 -
生产版是否按照您的预期过滤 web.xml?
jetty:run不起作用,我一点也不惊讶,因为jetty:run执行 unassembled webapp。当 war 插件作为包阶段的一部分运行时会发生过滤,jetty:run不使用 IIRC。您可能需要做一些研究来弄清楚如何让码头进行过滤。或者,您可能需要针对完全组装的 web 应用使用 jetty。 -
是的,你是对的!在为生产构建时,组装的 webapp 包含一个过滤的
web.xml。我只需要将filteringDeploymentDescriptor设置为 true 即可实现此目的。老实说,我之前没有尝试过为生产而构建。所以现在我只需要弄清楚如何为 jetty-maven-plugin 启用 web.xml 过滤。到目前为止感谢
标签: jakarta-ee maven web.xml maven-jetty-plugin