17

Is there a Java equivalent of .NET's System.Version class? How do I say this in Java?

Version myVersion = new Version(2, 1);
Jason Crease
  • 1,896
  • 17
  • 17
  • 1
    What properties of the version object do you need? Just a major / minor / revision / build tuple, or the conversion to / from binary, or the comparators, or something else? – Rup Mar 27 '12 at 14:06
  • Really just the major/minor tuple and comparators. I guess I could implement it myself, but was hoping for a readymade class. – Jason Crease Mar 27 '12 at 15:05
  • Yeah, I'm surprised there isn't one in Apache Commons or Google Guava (at least as far as I can see). – Rup Mar 27 '12 at 15:18

2 Answers2

1

To get a system/modules version e.g. String.class.getPackage().getImplementationVersion()

If you want to specify your own version, create a Manifest.txt file to be added to your jar-file as in this tutorial

See also the javadoc for Package

polve
  • 2,789
  • 2
  • 18
  • 20