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

  • Home
  • SEARCH
  • 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 4620052
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:30:29+00:00 2026-05-22T02:30:29+00:00

Admitted, this doesn’t sound like a best practice altogether, but let me explain. During

  • 0

Admitted, this doesn’t sound like a best practice altogether, but let me explain. During the build, we need to paste the build number and the system version into a class whose sole purpose is to contain these values and make them accessible.

Our first idea was to use system properties, but due to the volatility of the deployment environment (an other way of saying “the sysadmins are doing weird unholy creepy things”) we would like to have them hard-coded.

Essentially I see 4 possibilities to achieve it in ant :

  1. use <replace> on a token in the class

    The problem with this approach is that the file is changed, so you have to replace the token back after compilation with a <replaceregexp>…sooo ugly, I don’t want to touch source code with regex. Plus temporal dependencies.

  2. copy the file, make replace on the copy, compile copy, delete copy

    One one has to mind the sequence – the original class has to be compiled first in order to be overwritten by the copy. Temporal dependencies are ugly too.

  3. copy the file, replace the token on the original, compile, replace the stained original with the copy

    Same temporal dependency issue unless embedded in the compile target. Which is ugly too, because all our build files use the same imported compile target.

  4. create the file from scratch in the build script / store the file outside the source path

    Is an improvement over the first three as there are no temporal dependencies, but the compiler/IDE is very unhappy as it is oblivious of the class. The red markers are disturbingly ugly.

What are your thoughts on the alternatives?

Are there any best practices for this?

I sure hope I have missed a perfectly sane approach.

Thank you

EDIT
We ended up using the manifest to store the build number and system version in the Implementation-Version attribute, unsing MyClass.class.getPackage().getImplementationVersion(). I have found this solution was one of the answers to this thread, which was posted in the comment by andersoj

  • 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-22T02:30:29+00:00Added an answer on May 22, 2026 at 2:30 am

    I think a simpler approach would be to have your Version.java class read from a simple .properties file included in the JAR, and just generate this .properties file at build-time in the Ant build. For example just generate:

    build.number = 142
    build.timestamp = 5/12/2011 12:31
    

    The built-in <buildnumber> task in Ant does half of this already (see the second example).

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

Sidebar

Related Questions

I've been reading a little about temporary tables in MySQL but I'm an admitted
this is a bit of a newbie question but I can't seem to find
i use this code to split a data to make a list with three
i need some decision help today :-) interface A) an input field where the
'lo all. I am a self-described admitted noob in iPhone programming (having a much
I can't login to github with generated ssh-keys. I've followed this manual: http://help.github.com/linux-key-setup but
I'm trying to evaluate NHibernate.LINQ 1.0 without actually writing any code. Ayende has admitted
I would like to provide a templated function, that varies its implementation (->specialization) according
There's been a cluster of Perl-hate on Stack Overflow lately, so I thought I'd
I was greeted with a nasty bug today. The task is pretty trivial, all

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.