简体   繁体   English

蚂蚁脚本中的环境变量不起作用

[英]Environmental variables in ant script not working

I'm trying to set up a machine-independent build environment for a Spring framework project, and my ant configuration appears to be not working. 我正在尝试为Spring框架项目建立一个与机器无关的构建环境,而我的ant配置似乎无法正常工作。 I've searched quite a bit but everyone seems to think that env.* references work out of the box. 我搜索了很多,但似乎每个人都认为env。*引用开箱即用。 Could someone perhaps find the error of my ways? 有人可能会发现我的方式错误吗?

The error: 错误:

bash-3.1$ ant build
Buildfile: c:\Users\mkumpan\Projects\Spring testing\build.xml

BUILD FAILED
c:\Users\mkumpan\Projects\Spring testing\build.xml:85: c:\Users\mkumpan\Projects\Spring testing\${env.CATALINA_HOME}\lib does not exist.

build.xml:85: build.xml文件:85:

<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>

catalina-ant-classpath reference: catalina-ant-classpath参考:

<path id="catalina-ant-classpath">
    <fileset dir="${appserver.lib}">
        <include name="catalina-ant.jar"/>
    </fileset>
</path>

${appserver.lib} declared in build.properties: 在build.properties中声明$ {appserver.lib}:

appserver.home=${env.CATALINA_HOME}
appserver.lib=${appserver.home}/lib

deploy.path=${appserver.home}/webapps

Echoing the envvar works: 与envvar相呼应:

bash-3.1$ echo $CATALINA_HOME
C:\Program Files\Tomcat

The two big questions: 两大问题:

  • Why the hell does it not parse out the envvar? 为什么它不能解析envvar?
  • Why the hell does it prepend the absolute path to the envvar? 它到底为什么会在envvar的绝对路径之前?

Add the following line to the build.xml file: build.xml下行添加到build.xml文件中:

<property environment="env"/>

to define the prefix when referencing environment variables. 在引用环境变量时定义前缀。 From the Property reference page for the environment attribute: 环境属性的Property参考页面:

the prefix to use when retrieving environment variables. 检索环境变量时使用的前缀。 Thus if you specify environment="myenv" you will be able to access OS-specific environment variables via property names "myenv.PATH" or "myenv.TERM". 因此,如果指定environment =“myenv”,您将能够通过属性名称“myenv.PATH”或“myenv.TERM”访问特定于操作系统的环境变量。 Note that if you supply a property name with a final "." 请注意,如果您提供带有最终“。”的属性名称。 it will not be doubled; 它不会加倍; ie environment="myenv." 即环境=“myenv。” will still allow access of environment variables through "myenv.PATH" and "myenv.TERM". 仍然允许通过“myenv.PATH”和“myenv.TERM”访问环境变量。 This functionality is currently only implemented on select platforms. 此功能目前仅在特定平台上实现。 Feel free to send patches to increase the number of platforms on which this functionality is supported ;). 随意发送补丁以增加支持此功能的平台数量;)。 Note also that properties are case-sensitive, even if the environment variables on your operating system are not; 另请注意,即使操作系统上的环境变量不是,属性也区分大小写; eg Windows 2000's system path variable is set to an Ant property named "env.Path" rather than "env.PATH". 例如,Windows 2000的系统路径变量设置为名为“env.Path”的Ant属性,而不是“env.PATH”。

I hope you are declaring <property environment="env."/> before using env. 我希望你在使用env.之前声明<property environment="env."/> env. notation. 符号。

Also, below is the syntax in your build script to set specific environment variables. 此外,下面是构建脚本中用于设置特定环境变量的语法。

**Windows and OS/2**

Assume Ant is installed in c:\\ant. 假设Ant安装在c:\\ ant中。 The following sets up the environment: 以下设置环境:

set ANT_HOME=c:\ant
set JAVA_HOME=c:\jdk-1.5.0.05
set PATH=%PATH%;%ANT_HOME%\bin

**Linux/Unix (bash)**

Assume Ant is installed in /usr/local/ant. 假设Ant安装在/ usr / local / ant中。 The following sets up the environment: 以下设置环境:

export ANT_HOME=/usr/local/ant
export JAVA_HOME=/usr/local/jdk-1.5.0.05
export PATH=${PATH}:${ANT_HOME}/bin

**Linux/Unix (csh)**

setenv ANT_HOME /usr/local/ant
setenv JAVA_HOME /usr/local/jdk/jdk-1.5.0.05
set path=( $path $ANT_HOME/bin )

Having a symbolic link set up to point to the JVM/JDK version makes updates more seamless. 将符号链接设置为指向JVM / JDK版本可使更新更加无缝。

如果其他人仍在努力完成这项工作(就像我一样),而你不能(或者不愿意)对所有属性使用export ,请尝试按照此处的建议set -a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM