简体   繁体   中英

Order of compilation in ant target

The ant compile target below compiles all .java files in any of the src folders specified using a <src path="..."/> tag. My question is about the order of compilation. Does ant first compile the files referenced by the first src tag (ie does it first compile the Java files in ${xtext.project.path}/src ), then the second src tag, etc.? What order are the files compiled in? I'm trying to figure out the dependencies between folders and wonder if the order they are listed tells me anything.

 <target name="compile">
        <echo message="${ant.project.name}: ${ant.file}"/>

        <deps-load-path conf="core"   pathid="core.ivy.classpath" />
        <deps-load-path conf="test"   pathid="test.ivy.classpath" />

        <javac debug="true" includeantruntime="false" debuglevel="source,lines,vars" destdir="${bin.path}" source="1.8" target="1.8">
            <src path="${xtext.project.path}/src"/>
          <src path="${xtext.project.path}/src-gen"/>
          <src path="${project.path}/src"/>
          <src path="${project.path}/src-gen-umpletl"/>
          <src path="${project.path}/src-gen-umple"/>
          <src path="${project.path}/test"/>
          <src path="${vendors.path}/jopt-simple/src"/>
          <exclude name="**/.git"/>
          <exclude name="**/*.ump" />
          <exclude name="**/data" />
          <classpath refid="project.classpath"/>
          <classpath refid="validator.project.classpath"/>
          <classpath refid="core.ivy.classpath" />
          <classpath refid="test.ivy.classpath" />
            <!-- Add compiler arguments here, see https://ant.apache.org/manual/using.html#arg for details, example below
                  <compilerarg value="-Xlint:deprecation" />
            -->
        </javac>

        <copy todir="${bin.path}" overwrite="true">
            <fileset dir="${project.path}/src"><include name="**/*.grammar"/></fileset>
            <fileset dir="${project.path}/src"><include name="**/*.error"/></fileset>
        </copy>
        <delete file="cruise.umple/src/rules.grammar"/>
        <delete file="cruise.umple/bin/rules.grammar"/>
      </target>

You can see how <javac> compiles files by running Ant with the -verbose option.

For example, the following Ant script...

<javac debug="true" includeantruntime="false">
    <src path="src1"/>
    <src path="src2"/>
</javac>

...outputs the following with ant -verbose running on a Windows machine...

[javac] Compilation arguments:
[javac] '-classpath'
[javac] ''
[javac] '-sourcepath'
[javac] '.....\src1;.....\src2'
[javac] '-g'

In the above example, Ant combined the <src> elements into the semicolon-separated -sourcepath argument.

-sourcepath is an option of Oracle's javac tool :

-sourcepath sourcepath

Specifies the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by colons (:) on Oracle Solaris and semicolons on Windows and can be directories, JAR archives, or ZIP archives.

Note the distinction between Ant's <javac> task and Oracle's javac tool. The Ant <javac> task calls the Oracle javac tool.

For your question "What order are the files compiled in?", the answer is essentially: The Java files are all compiled at the same time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM