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 4019294
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:05:13+00:00 2026-05-20T10:05:13+00:00

I need to filter java files before compilation, leaving the original sources unchanged and

  • 0

I need to filter java files before compilation, leaving the original sources unchanged and compiling from filtered ones (basically, I need to set build date and such).
I’m using NetBeans with its great Ant build-files.

So, one day I discovered the need to pre-process my source files before compilation, and ran into a big problem. No, I did not run to SO at once, I did some research, but failed. So, here comes my sad story…

I found the “filter” option of “copy” task, overrided macrodef “j2seproject3:javac” in build-impl.xml file and added filter in the middle of it. I got the desired result, yes, but now my tests are not working, since they use that macrodef too.

Next, I tired to overriding “-do-compile” target, copying&filtering files to directory build/temp-src, and passing an argument of new source directory to “j2seproject3:javac”:

<target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,
        -compile-depend,-prepare-sources"
        if="have.sources" name="-do-compile">
    <j2seproject3:javac gensrcdir="${build.generated.sources.dir}" srcdir="build/temp-src"/>
    <copy todir="${build.classes.dir}">
        <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
    </copy>
</target>

And now Ant says to me, that macrodef in question does not exist!

The prefix "j2seproject3" for element "j2seproject3:javac" is not bound.

That’s strange, since build-impl.xml contains that macrodef, and build-impl.xml is imported into main build file.

And, by the way, I cannot edit build-impl.xml directly, since NetBeans rewrites it on every other build.

So, my question is: how can I automatically filter sources before compiling in NetBeans, and do not break the build process?

  • 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-20T10:05:14+00:00Added an answer on May 20, 2026 at 10:05 am

    Looking at the default build.xml, it contains a comment that reads (in part):

    There exist several targets which are by default empty and which can be 
    used for execution of your tasks. These targets are usually executed 
    before and after some main targets. They are: 
    
      -pre-init:                 called before initialization of project properties
      -post-init:                called after initialization of project properties
      -pre-compile:              called before javac compilation
      -post-compile:             called after javac compilation
      -pre-compile-single:       called before javac compilation of single file
      -post-compile-single:      called after javac compilation of single file
      -pre-compile-test:         called before javac compilation of JUnit tests
      -post-compile-test:        called after javac compilation of JUnit tests
      -pre-compile-test-single:  called before javac compilation of single JUnit test
      -post-compile-test-single: called after javac compilation of single JUunit test
      -pre-jar:                  called before JAR building
      -post-jar:                 called after JAR building
      -post-clean:               called after cleaning build products
    

    So, to inject some pre-compile processing, you would provide a definition for -pre-compile.

    FWIW, the error you got is because the j2seprojectX prefix is defined on the project tag of build-impl.xml, and the code in build.xml is outside of that tag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

short: I need to filter all .java files and every META-INF folder from a
I need to filter result sets from sql server based on selections from a
I need to filter alphabetic and non alphanumeric characters from a string to make
For a website that takes input from kids we need to filter any naughty
I need to filter out anchor tags in a string. For instance, Check out
I need to filter out junk data in SQL (SQL Server 2008) table. I
I need a filter function for a project I'm working on. I am thinking
I need to filter a XPath expression to grab only a certain attribute as
I have some text i need to filter out a list of bad words
I need to return a list of counties, but I need to filter out

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.