How can I exclude sources in a javac task in ant?

后端 未结 6 1031
予麋鹿
予麋鹿 2021-01-01 18:26

I have the following in my build.xml:


   
            


        
相关标签:
6条回答
  • 2021-01-01 18:56

    Try

    <javac>
    (...>
    <exclude name="${src.dir}/com/foo/bar/quux/dontwant/*" />
    (...)
    </javac>
    
    0 讨论(0)
  • 2021-01-01 18:56

    If you are trying to exclude Java classes but Ant is still trying to compile them then this may be due to references to these classes in your code.

    If A.java has a reference to B.java and you try to exclude B.java then compiling A.java will require that B.java is compiled too.

    This is one reason for interfaces in Java, so you can compile the interface without needing to compile the implementations.

    0 讨论(0)
  • 2021-01-01 18:59

    I'm not sure about the rest, but the <exclude/> nested element should work in the Javac task. See the sixth example down.

    Addendum: Patterns, including the ** notation, are discussed in Directory-based Tasks.

    <target name="compile.baz" depends="init">
        <javac destdir="${build.dir}/classes" debug="on">
            <compilerarg value="-Xlint:deprecation"/>
            <src>
                <pathelement location="${src.dir}/com/foo/bar/baz/" />
                <pathelement location="${src.dir}/com/foo/bar/quux/" />
            </src>
            <exclude name="${src.dir}/com/foo/bar/quux/dontwant/**"/>
            ...
        </javac>
        ...
    </target>
    
    0 讨论(0)
  • 2021-01-01 19:00

    A couple of people suggested using <exclude>. This didn't work with the way my task was specified. trashgod's answer linked to the sixth example on this page which gave me an idea of how to restructure my task specification.

    It looks like my problem was related to the way I was specifying the source files. Rather than using <pathelement> elements in a <src>, like this:

    <src>
       <pathelement location="${src.dir}/com/foo/bar/baz/" />
       <pathelement location="${src.dir}/com/foo/bar/quux/" />
    </src>
    

    I switched to using a single <src> with a path and then a set of <include> elements, like this:

    <src path="${src.dir}" />
    <include name="com/foo/bar/baz/**" />
    <include name="com/foo/bar/quux/**" />
    

    This appears to be functionally identical, but is compatible with the use of <exclude>:

    <exclude name="${src.dir}/com/foo/bar/quux/dontwant/**"/>
    

    (Actually, I'm surprised that what was there in the first place worked at all.)

    0 讨论(0)
  • 2021-01-01 19:10

    try folder "test" under {source.dir} would not be complied

    <javac destdir="${compile.dir}"  ...>
       <src path="${source.dir}" />
       <exclude name="test/**"/>
    </javac>
    
    0 讨论(0)
  • 2021-01-01 19:22

    From my experiments you should not include full path for file you want to exclude. This one doesn't work:

    <javac>
    (...>
       <exclude name="${src.dir}/com/foo/blah/blah1/FILENAME.java"/>
    (...)
    </javac>
    

    but this one does:

    <javac>
    (...>
       <exclude name="com/foo/blah/blah1/FILENAME.java"/>
    (...)
    </javac>
    
    0 讨论(0)
提交回复
热议问题