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

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

问题描述

我正在尝试为 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"/>

在引用环境变量时定义前缀.来自 Property 参考页面的 environment 属性:

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

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

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天全站免登陆