为什么我的 build.properties 中的值没有通过我的 ant 构建传播?

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

我一直在研究一个用 ant 构建的 Java 项目,直到最近它都运行完美。现在我遇到了一些我不明白的错误(我是 ant 的新手),而且似乎有很多这样的错误。我已经挑出了其中一个,但潜在问题可能还有更多问题,所以如果我没有提供足够的信息,请向我询问更多信息。 =)

我解决的问题与我的 build.properties 文件、调用它的 commonbuild.xml 以及整个项目的根 build.xml 有关。当我从这样的命令行 运行 ant 时:

> ant

它输出:

(除了前 10 行我不会显示所有内容,但有人告诉我始终显示操作的完整输出)

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

在这里您可以看到我的调试尝试中的一些 echos。如果您查看 OUTPUT_DIR 的值,它评估为 classesenv.EMV_VOBSJAR_OUTPUT_DIR 也是如此,但 DEBUG_ONDEBUG_LVL 没有.这就是问题所在...并非 build.properties 中的所有值都被使用。

如果我 运行 蚂蚁是这样构建的:

>ant -propertyfile ./ant/build.properties

它输出这个:

    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

这对我来说很奇怪,因为 commonbuild.xml

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

应该导入我的 build.properties 文件,它有点...如果您查看 > ant 的输出,您会看到 OUTPUT_DIR = classes来自 build.properties 我假设。

所以...

这只是看起来很多的第一期,所以欢迎对下面的代码提出任何批评;我想尽我所能了解这些文件。

代码附录:

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>

常见build.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

对于那些感兴趣的人,我找到了问题的根源。

我在一台有多个分支的机器上工作。我被要求在我的机器上的 Main 分支中做一些事情,并设置一些环境变量,然后转到下一个问题。几周后,这些 ant 文件使用了相同的环境变量,当我去构建我的 Dev 分支时,我忘记了记住其中一个变量的重要性。我只改了一个,当然这是最重要的一个。 =/

所以最后,我尝试使用另一个代码库的 build.xml 文件编译一个代码库,并手动传递我的 build.properties,这进一步混淆了我的问题所在。这方面的教训?当我遇到问题时,我需要真正检查我的环境,而不仅仅是假设我已经正确设置了所有内容。

谢谢你看完我的遭遇,我要躲到角落里去了。 =)