我有一个 Web 应用程序 Maven 项目,我想根据正在运行的配置文件自定义 web.xml 文件。我正在使用 Maven-War-plugin,它允许我定义一个“资源”目录,可以在其中过滤文件。然而,仅靠过滤对我来说还不够。
更详细地说,我想要包括(或排除)关于安全性的整个部分,取决于我正在运行的配置文件。这是这部分:
....
....
<security-constraint>
<web-resource-collection>
<web-resource-name>protected</web-resource-name>
<url-pattern>/pages/*.xhtml</url-pattern>
<url-pattern>/pages/*.jsp</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>${web.modules.auth.type}</auth-method>
<realm-name>MyRealm</realm-name>
</login-config>
<security-constraint>
....
....
如果这不容易完成,是否有一种方法可以拥有两个 web.xml 文件并根据配置文件选择适当的一个?
有没有一种方法可以拥有两个 web.xml 文件并根据配置文件选择适当的一个?
是的,在每个配置文件中,您可以添加以下配置maven-war-plugin http://maven.apache.org/plugins/maven-war-plugin/并将每个配置为指向不同的web.xml
.
<profiles>
<profile>
<id>profile1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>/path/to/webXml1</webXml>
</configuration>
</plugin>
...
作为必须指定的替代方法maven-war-plugin http://maven.apache.org/plugins/maven-war-plugin/在每个配置文件中进行配置,您可以在 POM 的主要部分中提供默认配置,然后为特定配置文件覆盖它。
或者更简单地说,主要是<build><plugins>
您的 POM 中,使用属性来引用webXml
属性,然后在不同的配置文件中更改它的值
<properties>
<webXmlPath>path/to/default/webXml</webXmlPath>
</properties>
<profiles>
<profile>
<id>profile1</id>
<properties>
<webXmlPath>path/to/custom/webXml</webXmlPath>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>${webXmlPath}</webXml>
</configuration>
</plugin>
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)