ant不能读取java环境变量,在Ant脚本环境变量不工作

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?

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:

catalina-ant-classpath reference:

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

appserver.home=${env.CATALINA_HOME}

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

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

Echoing the envvar works:

bash-3.1$ echo $CATALINA_HOME

C:\Program Files\Tomcat

The two big questions:

Why the hell does it not parse out the envvar?

Why the hell does it prepend the absolute path to the envvar?

解决方案

Add the following line to the build.xml file:

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

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".

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值