简体   繁体   中英

ANT: ignore certain files from javac's sources

Currently, we define a path with

<path id="sources.production">
  <pathelement path="src/module1"/>
  <pathelement path="src/module2"/>
  ...
</path>

and then compile using

<javac ...>
   <src refid="sources.production"/>
   <classpath refid="classpath.production">
</javac>

Now we create some modified .java files (original files in src/module2 ) before this <javac> call and have put them before the other sources:

<path id="sources.production">
  <pathelement path="generated-sources"/>
  <pathelement path="src/module1"/>
  <pathelement path="src/module2"/>
  ...
</path>

Unfortunately, the compile fails now because the original and the modified .java files are both fed to the javac task. How to exclude the original source files easily from the javac's sources without large charges?

you need an intermediate step which you copy all your source files to a new location and override them with generated ones, then use this new location as source folder for javac .

it may look something like this:

<path id="sources.4compile" location="all-sources" />

<target name="prepare-4compile">

    <!-- clean -->
    <delete dir="all-sources"/>
    <mkdir dir="all-sources"/>

    <copy todir="all-sources">
        <fileset dir="src/module1"/>
        <fileset dir="src/module2"/>
        <fileset dir="generated-sources"/>
    </copy>

</target>

<target name="compile" depends="prepare-4compile">
    <javac ...>
       <src refid="sources.4compile" /> 
       <classpath refid="classpath.production" />
    </javac>
</target>

other way, you may specify a fileset to javac disabling javac's default searching mechanism as suggested here .

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