【问题标题】:What does this ${..} do for variables in ant?这个 ${..} 对 ant 中的变量有什么作用?
【发布时间】:2013-12-10 23:15:03
【问题描述】:

我正在尝试用 java 构建一个应用程序,但我收到一条错误消息:

/home/user/Documents/Installation_Files/csa/build2/rtiperftest.1.1b/perftest_java/build.xml:97: 执行失败:java.io.IOException:无法运行程序 “/home/user/Documents/Installation_Files/csa/build2/rtiperftest.1.1b/${env.NDDSHOME}/scripts/rtiddsgen” (在目录中 “/home/user/Documents/Installation_Files/csa/build2/rtiperftest.1.1b”): error=2, 没有这样的文件或目录

env.NDDSHOME 是需要设置的环境变量吗?

在 build.xml 文件中,我还看到了 ${rtidds.rtiddsgen}、${rtidds.home}、${script.suffix} 和其他具有 ${...} 语法的文件。这是什么意思?这些都是在环境变量中定义的吗?

这里是 build.xml 文件供参考:

<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: build.xml 2570 2009-05-28 14:42:37Z elaine $ Copyright 2006,
Real-Time Innovations. All rights reserved. No duplications, whole or
partial, manual or electronic, may be made without express written
permission. Any such copies, or revisions thereof, must display this
notice unaltered. This code contains trade secrets of Real-Time
Innovations, Inc. modification history:
=====================
17oct08,rbw Reorganized source files to make it easier to ship test
implementations separately 08oct08,rbw Refactored DDS dependencies to
com.rti.perftest.impl.PerfTestLauncher 20jun08,rbw javac path changes
23may08,rbw Enable preprocessor when running rtiddsgen to enable key
support 30apr08,rbw Fixed deletion order when cleaning 03apr08,rbw
Fail build when code gen fails 02apr08,rbw Created
========================================================================== -->
<project basedir=".." default="default" name="PerfTest">
  <!-- ===================================================================== -->
  <!-- End of $Id: build.xml 2570 2009-05-28 14:42:37Z elaine $ -->
  <description> A combined throughput and latency test for RTI Data Distribution Service in Java. </description>
  <!-- ================================================================= -->
  <!-- Public Targets -->
  <!-- ================================================================= -->
  <target name="default" description="Build a JAR file containing the test" depends="build-jar">
  </target>
  <target name="clean" description="Delete compiled code">
    <delete file="${jar.out.file}"/>
    <delete dir="${javac.out.dir}"/>
  </target>
  <!-- ================================================================= -->
  <!-- Internal Targets -->
  <!-- ================================================================= -->
  <target name="build-jar" depends="compile">
    <echo message="Building PerfTest JAR: ${jar.out.file}"/>
    <echo message="...containing classes: ${javac.out.dir}"/>
    <mkdir dir="${jar.out.dir}"/>
    <jar basedir="${javac.out.dir}" update="false" index="true" duplicate="fail" destfile="${jar.out.file}">
      <fileset dir="." includes="**/*.class"/>
      <manifest>
        <attribute name="Main-Class" value="com.rti.perftest.ddsimpl.PerfTestLauncher"/>
      </manifest>
    </jar>
  </target>
  <target name="compile" depends="generate">
    <echo message="Compiling PerfTest in dir: ${javac.out.dir}"/>
    <echo message="...using RTI DDS JAR file: ${rtidds.jar}"/>
    <mkdir dir="${javac.out.dir}"/>
    <javac target="1.5" optimize="${javac.optimize}" deprecation="${javac.deprecation}" debug="${javac.debug}" destdir="${javac.out.dir}" srcdir=".">
      <include name="perftest_java/**/*.java"/>
      <include name="perftest_java_util/**/*.java"/>
      <classpath>
        <pathelement path="${rtidds.jar}"/>
      </classpath>
    </javac>
  </target>
  <target name="generate" depends="properties">
    <echo message="Generating code with: ${rtidds.rtiddsgen} ${env.RTIDDSGEN_PREPROCESSOR} "/>
    <exec failonerror="true" failifexecutionfails="true" executable="${rtidds.rtiddsgen}">
      <arg line="-d perftest_java"/>
      <arg line="-language Java"/>
      <arg line="-package com.rti.perftest.gen"/>
      <arg line="-replace"/>
      <arg line="${env.RTIDDSGEN_PREPROCESSOR}"/>
      <arg file="idl/test.idl"/>
    </exec>
  </target>
  <target name="properties">
    <property environment="env"/>
    <property name="rtidds.home" location="${env.NDDSHOME}"/>
    <property name="rtidds.jar" location="${rtidds.home}/class/nddsjava.jar"/>
    <property name="env.RTIDDSGEN_PREPROCESSOR" value=""/>
    <condition value=".bat" else="" property="script.suffix">
      <os family="Windows"/>
    </condition>
    <property name="rtidds.rtiddsgen" location="${rtidds.home}/scripts/rtiddsgen${script.suffix}"/>
  </target>
</project>

【问题讨论】:

    标签: xml ant build


    【解决方案1】:

    ant 中,${property_name} 计算为绑定到名为 property_name 的属性的值。

    &lt;property environment="env"/&gt; 语句意味着将环境值绑定到env.。其他不带 env. 前缀的 ${ } 构造指的是其他非环境属性,通常在构建文件或外部属性文件中设置。

    因此,您的错误消息表明NDDSHOME 环境变量的设置存在问题。 ${env.NDDSHOME} 用于设置rtidds.home,用于指定rtidds.jar 的位置,也起到将rtidds.rtiddsgen 指定为${rtidds.home}/scripts/rtiddsgen${script.suffix} 的作用。该脚本可能希望您为本地安装正确设置。

    【讨论】:

      猜你喜欢
      • 2022-12-04
      • 1970-01-01
      • 1970-01-01
      • 2015-10-25
      • 1970-01-01
      • 2012-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多