5

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

我知道我可以在每个目录中使用单独的 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>

为了更好地衡量,profiles 部分具有以下配置:

  <profile>
    <id>dev</id>
    <properties>
      <env>dev</env>
    </properties>
  </profile>

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

我在吠叫错误的树吗?

谢谢,

埃里克

4

1 回答 1

11

Actually, I've discovered a way to do this:

The jboss-web.xml looks like this now:

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

The property file looks like this:

 jbossweb.virtualhost=hostname
 jbossweb.contextroot=/

Then the pom section looks like this for the maven war plugin configuration:

                <webResources>
                    <resource>
                        <directory>src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <include>jboss-web.xml</include>
                        <targetPath>/WEB-INF</targetPath>
                    </resource>
                </webResources>

And the filters are defined above the plug ins section, but within the build section as follows:

    <filters>
        <filter>src/main/filters/filter-${env}.properties</filter>
    </filters>
于 2011-11-22T19:26:16.793 回答