Search code examples
javaxmlantjavacbuild.xml

Why are values in my build.properties not propagating through my ant build?


I've been working on a Java project that is built with ant, and until recently it was working flawlessly. Now I'm getting some errors that I don't understand (I'm new to ant) and there appear to be quite a few of them. I've teased out one of them, but there may be more issues to the underlying problem, so if I don't give enough information, please ask me for more. =)

The problem I've teased out relates to my build.properties file, the commonbuild.xml that calls it, and the root build.xml for the whole project. When I run ant from the command line like this:

> ant

It outputs:

(I wouldn't show all but the first 10 lines, but I've been told to always show the full output of an action)

C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv>ant
Buildfile: C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\build.xml
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = ${DEBUG_ON}
     [echo] DEBUG_LVL = ${DEBUG_LVL}

buildSubDirs:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = ${DEBUG_ON}
     [echo] DEBUG_LVL = ${DEBUG_LVL}

subdirs:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = ${DEBUG_ON}
     [echo] DEBUG_LVL = ${DEBUG_LVL}

echo_name:
     [echo] idl

init:

create_dirs:

compile:
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\idl\build.xml:55: warning: 'includeantruntime' was not set, defaulting to build.sy
sclasspath=last; set to false for repeatable builds

build:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = ${DEBUG_ON}
     [echo] DEBUG_LVL = ${DEBUG_LVL}

buildSubDirs:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = ${DEBUG_ON}
     [echo] DEBUG_LVL = ${DEBUG_LVL}

subdirs:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = ${DEBUG_ON}
     [echo] DEBUG_LVL = ${DEBUG_LVL}

buildSubDirs:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = ${DEBUG_ON}
     [echo] DEBUG_LVL = ${DEBUG_LVL}

subdirs:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = ${DEBUG_ON}
     [echo] DEBUG_LVL = ${DEBUG_LVL}

echo_name:
     [echo] AddDefDbNavView

init:

create_dirs:

compile:
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\AddDefaultDbNavView\build.xml:7: warning: 'includeantruntime' was n
ot set, defaulting to build.sysclasspath=last; set to false for repeatable builds

make_jar:

build:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = ${DEBUG_ON}
     [echo] DEBUG_LVL = ${DEBUG_LVL}

echo_name:
     [echo] EmvDbTrans

init:

create_dirs:

compile:
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvDbToOracle\build.xml:7: warning: 'includeantruntime' was not set
, defaulting to build.sysclasspath=last; set to false for repeatable builds

make_jar:

build:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = ${DEBUG_ON}
     [echo] DEBUG_LVL = ${DEBUG_LVL}

echo_name:
     [echo] EmvUtils

init:

create_dirs:

compile:
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\build.xml:7: warning: 'includeantruntime' was not set, def
aulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 10 source files to C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\classes
    [javac]
    [javac]           WARNING
    [javac]
    [javac] The -source switch defaults to 1.8 in JDK 1.8.
    [javac] If you specify -target 1.5 you now must also specify -source 1.5.
    [javac] Ant will implicitly add -source 1.5 for you.  Please change your build file.
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.5
    [javac] warning: [options] source value 1.5 is obsolete and will be removed in a future release
    [javac] warning: [options] target value 1.5 is obsolete and will be removed in a future release
    [javac] warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\src\EmvUtils\EmvConnectionManager.java:41: error: package
EmvIdl does not exist
    [javac]     public EmvIdl.EmvSessionManager m_emv_session_manager;
    [javac]                  ^
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\src\EmvUtils\EmvConnectionManager.java:46: error: package
EmvIdl does not exist
    [javac]     public EmvIdl.AdminServer m_admin_server;
    [javac]                  ^
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\src\EmvUtils\EmvConnectionManager.java:51: error: package
EmvIdl does not exist
    [javac]     public EmvIdl.FigureToPngImage m_figure_to_png_image_server;
    [javac]                  ^
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\src\EmvUtils\EmvConnectionManager.java:189: error: package
 EmvIdl does not exist
    [javac]             m_emv_session_manager = EmvIdl.EmvSessionManagerHelper.narrow(obj);
    [javac]                                           ^
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\src\EmvUtils\EmvConnectionManager.java:219: error: package
 EmvIdl does not exist
    [javac]             m_admin_server = EmvIdl.AdminServerHelper.narrow(obj);
    [javac]                                    ^
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\src\EmvUtils\EmvConnectionManager.java:252: error: package
 EmvIdl does not exist
    [javac]             m_figure_to_png_image_server = EmvIdl.FigureToPngImageHelper.narrow(obj);
    [javac]                                                  ^
    [javac] Note: C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\src\EmvUtils\web\DumpRequest.java uses or overrides
a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\src\EmvUtils\web\DumpRequest.java uses unchecked or
unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 6 errors
    [javac] 4 warnings

BUILD FAILED
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\ant\commonbuild.xml:12: The following error occurred while executing this line:
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\build.xml:30: The following error occurred while executing this line:
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\ant\commonbuild.xml:12: The following error occurred while executing this line:
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\build.xml:6: The following error occurred while executing this line:
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\ant\commonbuild.xml:12: The following error occurred while executing this line:
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\build.xml:8: The following error occurred while executing this line:
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\build.xml:7: Compile failed; see the compiler error output for details
.

Total time: 1 second

Here you can see some echos from my debugging attempts. If you look at the value of OUTPUT_DIR it evaluated to classes, and so did env.EMV_VOBS and JAR_OUTPUT_DIR, but DEBUG_ON and DEBUG_LVL did not. This is the problem...not all of the values from build.properties are being used.

If instead I run the ant build like this:

>ant -propertyfile ./ant/build.properties

It outputs this:

    C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv>ant -propertyfile ./ant/build.properties
Buildfile: C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\build.xml
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = on
     [echo] DEBUG_LVL = lines,vars,source

buildSubDirs:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = on
     [echo] DEBUG_LVL = lines,vars,source

subdirs:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = on
     [echo] DEBUG_LVL = lines,vars,source

echo_name:
     [echo] idl

init:

create_dirs:

compile:
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\idl\build.xml:55: warning: 'includeantruntime' was not set, defaulting to build.sy
sclasspath=last; set to false for repeatable builds

build:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = on
     [echo] DEBUG_LVL = lines,vars,source

buildSubDirs:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = on
     [echo] DEBUG_LVL = lines,vars,source

subdirs:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = on
     [echo] DEBUG_LVL = lines,vars,source

buildSubDirs:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = on
     [echo] DEBUG_LVL = lines,vars,source

subdirs:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = on
     [echo] DEBUG_LVL = lines,vars,source

echo_name:
     [echo] AddDefDbNavView

init:

create_dirs:

compile:
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\AddDefaultDbNavView\build.xml:7: warning: 'includeantruntime' was n
ot set, defaulting to build.sysclasspath=last; set to false for repeatable builds

make_jar:

build:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = on
     [echo] DEBUG_LVL = lines,vars,source

echo_name:
     [echo] EmvDbTrans

init:

create_dirs:
    [mkdir] Created dir: C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvDbToOracle\${env.EMV_JAR_OUTPUT}

compile:
    [javac] C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvDbToOracle\build.xml:7: warning: 'includeantruntime' was not set
, defaulting to build.sysclasspath=last; set to false for repeatable builds

make_jar:
      [jar] Building jar: C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvDbToOracle\${env.EMV_JAR_OUTPUT}\EmvDbTrans.jar

build:
     [echo] env.EMV_VOBS = C:\Depot\afischer_L09691\Mvision\MAIN\
     [echo] OUTPUT_DIR = classes
     [echo] JAR_OUTPUT_DIR = C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\jar\Veracode
     [echo] DEBUG_ON = on
     [echo] DEBUG_LVL = lines,vars,source
..............
    [javac] Note: C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\src\EmvUtils\web\DumpRequest.java uses unchecked or
unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 30 errors
    [javac] 4 warnings

BUILD FAILED
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\ant\commonbuild.xml:12: The following error occurred while executing this line:
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\build.xml:30: The following error occurred while executing this line:
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\ant\commonbuild.xml:12: The following error occurred while executing this line:
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\build.xml:6: The following error occurred while executing this line:
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\ant\commonbuild.xml:12: The following error occurred while executing this line:
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\build.xml:8: The following error occurred while executing this line:
C:\Depot\afischer_L09691\Mvision\Dev\EMV_VERACODE\emv\utilities\java\EmvUtils\build.xml:7: Compile failed; see the compiler error output for details
.

Total time: 1 second

This is odd to me because the third line of commonbuild.xml

<property file="${env.EMV_VOBS}/emv/ant/build.properties"/>

is supposed to import my build.properties file, and it kind of is... If you look at the output from > ant you'll see that OUTPUT_DIR = classes which was taken from build.properties I assume.

So...

  • Why are some of the values in build.properties being used while other's aren't?
  • What other problems do you see with these files?

This is only the first issue of what seems like many, so any critiques of the code below is welcome; I want to understand everything I can about these files.

Code Appendix:

build.xml:

<!--

To run this, type in ant in the emv vobs directory (c:\view\emv)

    ant clean  - to clean the build environment
    ant        - to build the environment
-->
<project name="Emv" default="build" basedir=".">

    <import file="ant/commonbuild.xml" />

    <target name="subdirs">   
        <ant dir="idl" target="${param1}"/>    
        <ant dir="utilities" target="${param1}"/>    
        <ant dir="admin_panel" target="${param1}"/>   
        <ant dir="emv_monitor" target="${param1}"/>    
        <ant dir="integratedClient" target="${param1}"/>    
        <ant dir="web_server" target="${param1}"/>    
        <ant dir="XY-Graphics" target="${param1}"/>    
    </target>

    <target name="build" depends="buildSubDirs" />
    <target name="clean" depends="cleanSubDirs" />

</project>

commonbuild.xml:

<project name="commonbuild" default="buildSubDirs" basedir=".">

  <property environment="env"/> 
    <property file="${env.EMV_VOBS}/emv/ant/build.properties"/>
    <echo message="env.EMV_VOBS = ${env.EMV_VOBS}"/>
    <echo message="OUTPUT_DIR = ${OUTPUT_DIR}"/>
    <echo message="JAR_OUTPUT_DIR = ${env.EMV_JAR_OUTPUT}"/>
    <echo message="DEBUG_ON = ${DEBUG_ON}"/>
    <echo message="DEBUG_LVL = ${DEBUG_LVL}"/>

    <target name="buildSubDirs">  
        <antcall target="subdirs">    
            <param name="param1" value="build"/>  
        </antcall>
    </target>

    <target name="cleanSubDirs">  
        <antcall target="subdirs">    
            <param name="param1" value="clean"/>  
        </antcall>
    </target>

  <target name="echo_name" depends="">
    <echo message="${ant.project.name}"/>
  </target>

  <target name="init" depends="echo_name">
     <property name="project_name"   value="${ant.project.name}"/>
     <property name="jar"            value="${JAR_OUTPUT_DIR}/${project_name}.jar"/>
    <tstamp/>
  </target>

  <target name="clean" depends="init">
    <delete dir="${OUTPUT_DIR}"/>
    <delete file="${jar}"/>
  </target>

  <target name="create_dirs" depends="init">
    <mkdir dir="${OUTPUT_DIR}"/>
    <mkdir dir="${JAR_OUTPUT_DIR}"/>
  </target>

</project>

build.properties:

OUTPUT_DIR=classes
DEBUG_ON=on
DEBUG_LVL=lines,vars,source
JAR_OUTPUT_DIR=${env.EMV_JAR_OUTPUT}
TOMCAT_HOME=${env.TOMCAT_HOME}
ant.build.javac.target=1.5

Solution

  • For those interested, I found the source of my problem.

    I'm working on a machine with multiple branches. I was asked to do something in the Main branch on my machine, and set some environment variables, and moved on to the next issue. Several weeks later, these ant files use those same environment variables, and when I went to build my Dev branch, I neglected to remember how important one of those variables was. I changed all but one, and of course it was the most important one. =/

    So in the end, I was trying to compile one code base using the build.xml files from another, and passing my build.properties in manually, which further obfuscated what my issue was. The lesson in this? I need to really check my environment when I have issues, not just assume I've set everything correctly.

    Thank you for reading my plight, I'm going to go hide in a corner. =)