蚂蚁脚本中的环境变量不工作 [英] Environmental variables in ant script not working

查看:191
本文介绍了蚂蚁脚本中的环境变量不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Spring框架项目设置一个独立于机器的构建环境,而我的ant配置似乎不起作用。我搜索了很多,但每个人似乎都认为env。*参考文献是开箱即用的。有人可能会发现我的错误吗?

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. I've searched quite a bit but everyone seems to think that env.* references work out of the box. Could someone perhaps find the error of my ways?

错误:

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参考:

catalina-ant-classpath reference:

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

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

${appserver.lib} declared in build.properties:

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

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

回应envvar的作品:

Echoing the envvar works:

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

两个大问题:


  • 为什么会这样没有解析出envvar?

  • 为什么地狱前提到envvar的绝对路径?

推荐答案

将以下行添加到 build.xml 文件中:

Add the following line to the build.xml file:

<property environment="env"/>

在引用环境变量时定义前缀。从环境属性的属性参考页面:

to define the prefix when referencing environment variables. From the Property reference page for the environment attribute:


检索环境变量时使用的前缀。因此,如果您指定environment =myenv,您将能够通过属性名称myenv.PATH或myenv.TERM访问特定于OS的环境变量。请注意,如果您提供一个属性名称与最终它不会翻倍;即环境=myenv。仍然允许通过myenv.PATH和myenv.TERM访问环境变量。此功能目前仅在特定平台上实现。随意发送补丁以增加支持此功能的平台数量;)。
还要注意,属性是区分大小写的,即使操作系统上的环境变量不是;例如Windows 2000的系统路径变量设置为名为env.Path的Ant属性,而不是env.PATH。

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". Note that if you supply a property name with a final "." it will not be doubled; i.e. environment="myenv." will still allow access of environment variables through "myenv.PATH" and "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; e.g. Windows 2000's system path variable is set to an Ant property named "env.Path" rather than "env.PATH".

这篇关于蚂蚁脚本中的环境变量不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆