Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: How do I generate a build number or datettimestamp that I can access in my app?

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do I generate a build number or datettimestamp that I can access in my app?

    I'm a beginner with Java. I'm using NetBeans to build my app. Can someone explain in simple terms how to automatically create either a build number (e.g. that's incremented every time I rebuild) or a date and timestamp of the build that I can then access in my application? This is simply so I can record in my log files which version of the program created them. I'm going through multiple builds per day and it's essential that I know which version created what output...

    I found this useful article (Use ANT to Build a JAR with version/build number - Real's Java How-to), but I don't know enough about how NetBeans uses Ant to implement it within NB.

    Thanks - Rowan


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How do I generate a build number or datettimestamp that I can access in my app?

    Great idea. I have always had to do it manually. However I don't use ant (I use batch files to build my jar files) so I still won't be able to do it.
    It has given me an idea that I'll have to work on.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How do I generate a build number or datettimestamp that I can access in my app?

    Typically when I deploy applications, I modify the deploy date and versioning in the class that holds the main method - the first line of which is an info() method call of a logging library that prints out this information the the logger appenders. (One can do a similar things with System.out.println) To automate, you can build your app using something like ANT, and write a file containing the timestamp information which is packaged in the deployed application. This can be read as a resource and accessed accordingly.

  4. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do I generate a build number or datettimestamp that I can access in my app?

    Quote Originally Posted by copeg View Post
    To automate, you can build your app using something like ANT, and write a file containing the timestamp information which is packaged in the deployed application. This can be read as a resource and accessed accordingly.
    Yes, that's what I have in mind to do, but unfortunately don't know enough about how NetBeans uses Ant, or about Ant itself, to know what script to write to do this, or where to write it. Can anyone help with this?

    Thanks - Rowan

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do I generate a build number or datettimestamp that I can access in my app?

    Quote Originally Posted by Norm View Post
    I use batch files to build my jar files ... so I still won't be able to do it.
    I can't see why you should not do this in a batch file if you can remember all that arcane stuff from the 1980s about writing batch files. It always amazes me what can be achieved in a such a crude language with enough ingenuity :-).

    Rowan

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How do I generate a build number or datettimestamp that I can access in my app?

    I could write a utility program to update the manifest and use it in the batch file.

Similar Threads

  1. generate a random number from 100 to 150, inclusive in applet
    By chonch in forum Java Theory & Questions
    Replies: 12
    Last Post: February 14th, 2014, 05:44 AM
  2. Generation of random number using random class
    By JavaPF in forum Java SE API Tutorials
    Replies: 1
    Last Post: December 7th, 2011, 05:46 PM
  3. Creating a new class and dont know how to generate a random number math code
    By beatlebaby70 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 15th, 2011, 03:03 PM
  4. Default Access (package access) confusion
    By gauravrajbehl in forum Java Theory & Questions
    Replies: 1
    Last Post: November 18th, 2009, 04:11 AM
  5. Generation of random number using random class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 16th, 2009, 06:10 AM