Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

catalina-ant-classpath reference:

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

${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?
like image 233
Maxim Kumpan Avatar asked Sep 10 '13 08:09

Maxim Kumpan


People also ask

How do I set an Ant environment variable in Windows?

Choose Start -> Control Panel, and double-click the System icon. Click the Advanced tab, and then click the Environment Variables button. Under System Variables, select New to create the ANT_HOME environment variable.

How do I set an environment variable in Python?

To permanently modify the default environment variables, click Start and search for 'edit environment variables', or open System properties, Advanced system settings and click the Environment Variables button. In this dialog, you can add or modify User and System variables.

How do I run an Ant script from the command line?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

What is build xml in Ant?

The build. xml file contains information that the wsgen Java Ant task uses to assemble Web services into Enterprise Application archive (*. ear) files.


1 Answers

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:

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

like image 111
hmjd Avatar answered Oct 28 '22 14:10

hmjd