【问题标题】:Maven errors to get a property from another pom从另一个 pom 获取属性的 Maven 错误
【发布时间】:2023-01-20 21:45:29
【问题描述】:

我有 3 个 pom.xml, 在一个 pom 中,我有测试/产品的配置文件..,根据哪个处于活动状态,可以选择 2 个文件夹,问题是当我更新 maven 时出现此错误:

     on project projWeb: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:3.2.2:war fai
led: basedir C:\Progetti\Proj\sviluppo\archicon\projWeb\src\main\webapp\WEB-INF\jbossWeb\${current.jbossWeb} does not exist -

在父 pom 我有这个:C:\Progetti\Proj\sviluppo\proj\pom.xml

  <modelVersion>4.0.0</modelVersion>
<groupId>it.sisal</groupId>
<artifactId>proj</artifactId>
<version>${appVersion}</version>
<packaging>pom</packaging>
<name>Proj</name>
<modules>
    <module>projWeb</module>
    <module>projEAR</module>
</modules>
....
<profile>
            <id>test</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <environment.profile>test</environment.profile>
                <current.jbossWeb>securityOff</current.jbossWeb>
            </properties>
        </profile>

在我的孩子 pom.xml 中:C:\Progetti\Proj\sviluppo\proj\projWeb\pom.xml

 <modelVersion>4.0.0</modelVersion>
    <groupId>it.sisal</groupId>
    <artifactId>projWeb</artifactId>
    <packaging>war</packaging>
    <version>0.0.40-SNAPSHOT</version>
    <name>Proj Web</name>

    <parent>
        <artifactId>proj</artifactId>
        <groupId>it.sisal</groupId>
        <version>${appVersion}</version>
    </parent>
 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <!--                    <warSourceDirectory>${project.basedir}/WebContent</warSourceDirectory> -->
                    <webXml>${current.webXml}</webXml>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <!--                    <warSourceExcludes>css/</warSourceExcludes> -->
                    <webResources>
                        <resource>
                            <directory>${jbossWeb.folder}/${current.jbossWeb}</directory>
                            <targetPath>WEB-INF</targetPath>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

即使在 Intellij 中我也能看到:

有人能解释一下为什么我不能得到房产吗?请问我该如何解决。

【问题讨论】:

  • C:\Progetti\Proj\sviluppo\proj\pom.xml,你的${appVersion}在哪里
  • @life888888 感谢您的评论,它存储在 pom.cml <appVersion>0.0.40-SNAPSHOT</appVersion> 的属性中
  • 您的 test 个人资料会永远启用吗?因为你的属性current.jbossWeb是定义在test profile块中的,也就是如果未启用测试配置文件,应该没有 current.jbossWeb 属性集。
  • 您好,是的,每个配置文件都将属性值设置为 securityOff 或 securityOn,我正在尝试使用测试配置文件
  • 简单地回答这个:&lt;version&gt;${appVersion}&lt;/version&gt; 是行不通的。只有一种方法可以通过maven.apache.org/maven-ci-friendly.html 找到类似的东西(但确实推荐使用最新版本。)

标签: java xml maven pom.xml parent-pom


【解决方案1】:

在父 pom.xml (C:ProgettiProjsviluppoprojpom.xml) 中,添加属性,设置属性我的.current.jbossWeb参考配置文件的属性当前.jbossWeb

<properties>
        <my.current.jbossWeb>${current.jbossWeb}</my.current.jbossWeb>
</properties>

在子 pom.xml (C:ProgettiProjsviluppoprojprojWebpom.xml)

更改参考${current.jbossWeb}${my.current.jbossWeb}, 引用父pom, properties: property我的.current.jbossWeb, 不是个人资料的财产当前.jbossWeb

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-29
    • 2012-03-31
    • 2012-12-22
    • 2011-10-31
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多