【问题标题】:using maven variables defined in two separate profiles使用在两个单独的配置文件中定义的 Maven 变量
【发布时间】:2011-02-21 09:27:06
【问题描述】:

我的 pom.xml 中有两个配置文件,dev 和 stage:

<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <hostname>vl-wlp1.hk.oracle.com</hostname>
        </properties>
        <id>stage</id>
        <properties>
            <hostname>vl-wcfs.hk.oracle.com</hostname>
        </properties>
    </profile>
</profiles>

我想在我的网站文档中使用这些:

src/site/apt/index.apt

像这样:

Dev Site: ${dev.hostname}
Stage Site: ${stage.hostname}

我可以这样做或其他具有相同效果的东西吗?

【问题讨论】:

    标签: maven-2 maven profiles


    【解决方案1】:

    不是没有一个巨大的黑客,不。

    如果您想独立读取两个属性值,它们必须是两个不同的属性。

    这样的务实解决方案怎么样:

    <properties>
        <dev.host>vl-wlp1.hk.oracle.com</dev.host>
        <stage.host>vl-wcfs.hk.oracle.com</stage.host>
    </properties>
    
    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <hostname>${dev.host}</hostname>
            </properties>
            <id>stage</id>
            <properties>
                <hostname>${stage.host}</hostname>
            </properties>
        </profile>
    </profiles>
    

    src/site/apt/index.apt:

    Dev Site: ${dev.host}
    Stage Site: ${stage.host}
    

    (上面提到的巨大黑客意味着以编程方式迭代当前项目的配置文件并手动解析每个配置文件的属性,您可以在自定义 maven 插件或使用 GMaven 的 Groovy 脚本中执行此操作)

    【讨论】:

    • 如何根据构建配置文件在Java代码中使用主机名?
    • @manurajhada 你应该问一个单独的问题,但是:从属性文件中获取主机名并通过 maven 资源过滤运行它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-13
    • 2019-02-23
    • 1970-01-01
    • 2016-02-18
    • 2013-12-06
    • 1970-01-01
    • 2014-10-25
    相关资源
    最近更新 更多