【问题标题】:Ant property not setting correctly?Ant 属性设置不正确?
【发布时间】:2016-04-27 07:24:22
【问题描述】:

我对 ant 相当陌生,我不太清楚为什么 运行 ant 时出现以下错误:无法找到目标 java:请将 JAVA_HOME 设置为其位置。我在下面粘贴了相关的源代码。据我所知,目标 -check-langtools.jdk.home 正在执行。但是因为它依赖于-def-check,所以它会被执行。调用 -check-langtools.jdk.home 时,属性(名称、属性、标记)是否被传递到 -def-check 中?如果是这样 - 故障必须发生在未设置属性的情况下(即 isset 必须返回 false)。我不明白如何没有设置属性,如果它能够打印出值(即 JAVA_HOME)。

背景:尝试从 OpenJDK 构建 langtools

<target name="-def-check">
  <macrodef name="check">
      <attribute name="name"/>
      <attribute name="property"/>
      <attribute name="marker" default=""/>
        <sequential>
            <fail message="Cannot locate @{name}: please set @{property} to its location">  
                <condition>
                    <not>
                        <isset property="@{property}"/>
                    </not>
                </condition>
            </fail>
            <fail message="@{name} is not installed in ${@{property}}">
                <condition>
                    <and>
                        <not>
                            <equals arg1="@{marker}" arg2=""/>
                        </not>
                        <not>
                            <available file="${@{property}}/@{marker}"/>
                        </not>
                    </and>
                </condition>
            </fail>
        </sequential>
    </macrodef>
</target>

<target name="-check-langtools.jdk.home" depends="-def-check">
    <!-- <check name="target java" property="langtools.jdk.home" marker="${java.marker}"/>   -->
    <check name="target java" property="JAVA_HOME" marker="${java.marker}"/>
</target>

<target name="-check-jtreg.home" depends="-def-check">
    <check name="jtreg" property="jtreg.home" marker="lib/jtreg.jar"/>
</target>

【问题讨论】:

  • 取决于意味着run this before you run me
  • 那么我的问题是:运行的第一件事(“无法定位@{name}:请将@{property} 设置为其位置”)如何知道运行我的设置.例如找不到目标 java:请将 @{property} 设置为其位置,其中 property = JAVA_HOME
  • isset 正在寻找使用&lt;property&gt; 设置的属性
  • 为什么宏在目标???

标签: java ant openjdk


【解决方案1】:

这个问题有点像金发女郎,但我最终以错误的方式解决了这个问题,但如果有人是 Ant 的新手,并且希望做同样的事情,我会在这里发布答案。要构建 javac 的 langtools 部分,他们需要做的是在包含的单独 build.properties 文件中设置 langtools.jdk.home=path_to_jdk_installation。

(例如 langtools.jdk.home=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home)

【讨论】:

  • 不建议直接更改build.properties文件。您可以将此选项作为标志传递:ant -Dlangtools.jdk.home=/usr/lib/jvm/java-8-openjdk-amd64.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-16
  • 1970-01-01
  • 2023-03-19
  • 2014-02-04
  • 2015-01-11
  • 2013-03-06
相关资源
最近更新 更多