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);
3
  • 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
    Commented Mar 27, 2012 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. Commented Mar 27, 2012 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
    Commented Mar 27, 2012 at 15:18

2 Answers 2

2

Here's a class from OSGi: http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/Version.html

And the corresponding source: http://www.docjar.com/html/api/org/osgi/framework/Version.java.html

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

2
  • But I am afraid it is just a string in the end.
    – polve
    Commented Mar 27, 2012 at 15:07
  • 3
    I ended up implementing my own Version tuple, but thanks for the links, I've been using them! Commented Mar 30, 2012 at 10:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.