Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 665457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:42:36+00:00 2026-05-13T23:42:36+00:00

How can I get the javac task to use an existing fileset? In my

  • 0

How can I get the javac task to use an existing fileset? In my build.xml I have created several filesets to be used in multiple places throughout build file. Here is how they have been defined:

<fileset dir = "${src}"  
    id       = "java.source.all">  
 <include name =  "**/*.java" />  
</fileset>  

<fileset dir = "${src}"  
    id       = "java.source.examples">  
  <include name = "**/Examples/**/*.java" />  
</fileset>  

<fileset dir = "${src}"  
    id       = "java.source.tests">  
  <include name = "**/Tests/*.java" />
</fileset>

<fileset dir = "${src}"
    id       = "java.source.project">
  <include name = "**/*.java"             />
  <exclude name = "**/Examples/**/*.java" />
  <exclude name = "**/Tests/**/*.java"    />
</fileset>

I have also used macrodef to compile the java files so the javac task does not need to be repeated multiple times. The macro looks like this:

<macrodef name="compile">
  <attribute name="sourceref"/>
  <sequential>
    <javac srcdir         = "${src}"
        destdir           = "${build}"
        classpathref      = "classpath"
        includeantruntime = "no"
        debug             = "${debug}">
      <filelist dir="." files="@{sourceref}" />  <-- email is about this
   </javac>
 </sequential>

What I’m trying to do is compile only the classes that are needed for specific targets not all the targets in the source tree. And do so without having to specify the files every time. Here are how the targets are defined:

<target name = "compile-examples"
    depends  = "init">
  <compile sourceref = "${toString:java.source.examples}" />
</target>

<target name = "compile-project"
    depends  = "init">
  <compile sourceref = "${toString:java.source.project}" />
</target>

<target name = "compile-tests"
    depends  = "init">
  <compile sourceref = "${toString:java.source.tests}" />
</target>

As you can see each target specifies the java files to be compiled as a simi-colon separated list of absolute file names. The only problem with this is that javac does not support filelist. It also does not support fileset, path or pathset. I’ve tried using but it treats the list as a single file name. Another thing I tried is sending the reference directly (not using toString) and using but include does not have a ref attribute.

SO THE QUESTION IS: How do you get the javac task to use a reference to a fileset that was defined in another part of the build file? I’m not interested in solutions that cause me to have multiple javac tasks. Completely re-writting the macro is acceptable. Changes to the targets are also acceptable provided redundant code between targets is kept to a minimum.

p.s. Another problem is that fileset wants a comma separated list. I’ve only done a brief search for a way to convert semi-colons to commas and haven’t found a way to do that.

p.p.s. Sorry for the yelling but some people are too quick to post responses that don’t address the subject.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:42:37+00:00Added an answer on May 13, 2026 at 11:42 pm

    If I understand your question correctly, then a combination of antcall and pathconvert tasks should do the trick.

    Pathconvert can be used to carry out the comma-separating in the included file list.
    (I don’t understand what the semi-colon issue you mention in passing is, but you can probably adjust the pathconvert call to address that.)
    Using antcall in the macro allows you to pass a different fileset reference id on each compilation.

    Here’s an example that illustrates:

    <fileset id="file.set1" dir="." includes="TestT*.java" />
    <fileset id="file.set2" dir="." includes="TestF*.java" />
    
    <macrodef name="compile">
      <attribute name="sourceref"/>
      <sequential>
        <antcall target="compile_inner">
          <reference refid="@{sourceref}" torefid="inner.file.set" />
        </antcall>
      </sequential>
    </macrodef>
    
    <target name="comp">
      <compile sourceref="file.set1" />
      <compile sourceref="file.set2" />
    </target>
    
    <target name="compile_inner">
      <pathconvert pathsep=" " property="file.list" refid="inner.file.set">
        <map from="${basedir}/" to="" />
      </pathconvert>
      <javac srcdir         = "${src}"
          destdir           = "${build}"
          includeantruntime = "no"
          includes          = "${file.list}"
          debug             = "${debug}"
          listfiles         = "yes">
      </javac>
    </target>
    

    Running the comp target with files

    TestFive.java TestFour.java TestOne.java TestSix.java TestThree.java TestTwo.java
    

    in the ${src} dir yields:

    comp:
    
    compile_inner:
        [javac] Compiling 2 source files to /Users/mc/stack_overflow/ant/javac
        [javac] /Users/mc/stack_overflow/ant/javac/TestThree.java
        [javac] /Users/mc/stack_overflow/ant/javac/TestTwo.java
    
    compile_inner:
        [javac] Compiling 2 source files to /Users/mc/stack_overflow/ant/javac
        [javac] /Users/mc/stack_overflow/ant/javac/TestFive.java
        [javac] /Users/mc/stack_overflow/ant/javac/TestFour.java
    
    BUILD SUCCESSFUL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, i have some question about xml Documents in Java. Can i get all
How can I get java classes from an xml file? In this situation, I
How can I get output from Java anonymous classes? In .Net I would use
in Ant I want to execute a Java task on a fileset. I use
I have some automatically generated Ant build scripts that I need to use to
I have a method that performs some task with a timeout. I use the
I'm using Spring Security 3.0.7 How can I get with java code the access
How can I get an equivalent of java.lang.Integer.MIN_VALUE on C++?
How can I get video and audio streams from web cameras with Java (in
How can I get an entity manager in a normal java class? I tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.