gpt4 book ai didi

maven - jboss-web.xml 可以访问属性吗?

转载 作者:行者123 更新时间:2023-12-04 17:12:07 25 4
gpt4 key购买 nike

我正在尝试将我的项目设置为根据环境使用不同的虚拟主机名。

我知道我可以在每个目录中使用单独的 jboss-web.xml 文件创建目录。但是我最近将这个项目移到了 maven 并希望利用这些配置文件。我已经设置了数据库,因此可以通过配置文件使用过滤器对它们进行不同的配置。

jboss-web.xml:

<jboss-web>
<context-root>/</context-root>
<virtual-host>${jbossweb.virtualhost}</virtual-host>
</jboss-web>

环境特定的属性文件有一个条目:
jbossweb.virtualhost=hostname.domain.com

pom 文件构建部分有这个定义
    <filters>
<filter>src/main/filters/filter-${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
</resource>
</resources>

只是为了更好地衡量,配置文件部分具有以下配置:
  <profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
</profile>

我什至不确定我正在尝试做的事情是否可行。当我尝试时,Jboss-web.xml 在虚拟主机位置有变量名而不是值。

我是不是叫错了树?

谢谢,

埃里克

最佳答案

实际上,我发现了一种方法来做到这一点:

jboss-web.xml 现在看起来像这样:

<jboss-web>
<context-root>${jbossweb.contextroot}</context-root>
<virtual-host>${jbossweb.virtualhost}</virtual-host>
</jboss-web>

属性文件如下所示:
 jbossweb.virtualhost=hostname
jbossweb.contextroot=/

然后 pom 部分对于 maven war 插件配置如下所示:
                <webResources>
<resource>
<directory>src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<include>jboss-web.xml</include>
<targetPath>/WEB-INF</targetPath>
</resource>
</webResources>

过滤器定义在插件部分之上,但在构建部分中定义如下:
    <filters>
<filter>src/main/filters/filter-${env}.properties</filter>
</filters>

关于maven - jboss-web.xml 可以访问属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8225331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com