Question

I'm on Ubuntu 14.04 and am trying to access environment variables from inside an Ant build.xml file. I have tried running this buildscript from inside Eclipse's Ant View, as well as from the command-line using the Ant SDK.

From a shell, if I type echo $TOMCAT_HOME, I get /home/myuser/tomcat/7.0.41 as output (this is correct). Here is my build.xml:

<?xml version="1.0"?>
<project name="myapp" default="test-vars" basedir=".">
    <property environment="env" />

    <target name="test-vars">
        <echo message="TOMCAT_HOME is ${env.TOMCAT_HOME}" />
    </target>
</project>

When I run the test-vars target (again, both from inside Eclipse and the command-line):

Buildfile: /home/myuser/workspace/myapp/build.xml
test-vars:
    [echo] TOMCAT_HOME is ${env.TOMCAT_HOME}
BUILD SUCCESSFUL
Total time: 1 second

What is going on here? How can I fix this? Do I need to add TOMCAT_HOME to somewhere other than ~/.bashrc, like /etc/environment? If so, where/how?

Was it helpful?

Solution

I have a similar problem with KUbuntu 14.04, Eclipse Kepler and ANT. Here is what I did:

  1. goto Run -> External Tools -> External Tools Configurations ...

  2. Choose the configuration of your ant build

  3. Go to the Environment tab and add the environment variable using the "New" button

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top