Pom 文件不读取环境变量

Pom file not reading environment variables

更新:

如果我将 ${env.JAVA_HOME} 更改为系统 属性 ${java.home} 然后它会执行 maven-dependency-plugin unpack 复制 任务。但是现在它在 maven-ant运行-plugin:1.8:运行 (build-content).

上失败了
[ERROR] one of its dependencies could not be resolved: Could not find artifact ... at specified path ... -> [Help 1]

为什么它在 JRE 文件夹中寻找我的 jar 文件?

/{path to jdk}/Contents/Home/jre/lib/...

就在这里:

/{path to jdk}/Contents/Home/lib

我的 pom.xml 文件没有读取我的 JAVA_HOME 环境变量。我在 Mac。这是条目:

<dependencies>
    <dependency>
        <groupId>{groupId}</groupId>
        <artifactId>{artifactId}</artifactId>
        <version>${version}</version>
        <scope>system</scope>
        <systemPath>${env.JAVA_HOME}/lib/myPersonalJar.jar</systemPath>
    </dependency>
</dependencies>

这是错误:

[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'build.plugins.plugin[org.apache.maven.plugins:maven-antrun-plugin].dependencies.dependency.systemPath' for ... must specify an absolute path but is ${env.JAVA_HOME}/lib/myPersonalJar.jar

在 iTerm 应用程序中,我可以回显 $JAVA_HOME 并且它指向正确的位置。

当我将 systemPath 硬编码到我的 Java 家时,它工作得很好。我不知道为什么。为了提供一些上下文,我的 ant 构建文件也没有读取我的环境变量。

我是不是遗漏了一些简单的愚蠢的东西?

尝试将此配置文件添加到您的 pom.xml(在 <profiles/> 中):

<profile>
  <id>tools.jar</id>
  <activation>
    <file><exists>${java.home}/../lib/tools.jar</exists></file>
  </activation>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>jdk</groupId>
        <artifactId>tools</artifactId>
        <version>${java.specification.version}</version>
        <scope>system</scope>
        <systemPath>${java.home}/../lib/tools.jar</systemPath>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-antrun-plugin</artifactId>
          <dependencies>
            <dependency>
              <groupId>jdk</groupId>
              <artifactId>tools</artifactId>
              <version>${java.specification.version}</version>
              <scope>system</scope>
              <systemPath>${java.home}/../lib/tools.jar</systemPath>
            </dependency>
          </dependencies>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>
          <configuration>
            <docletPath>${tools.jar}</docletPath>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</profile>

我已经包含了对 javadoc plug-in 的相应更改,这可能或 可能对你没有用。如果你不需要它,你可以删除它。