Java equivalent of .NET's Version class?
Asked Answered
A

3

18

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

Version myVersion = new Version(2, 1);
Alee answered 27/3, 2012 at 14:4 Comment(3)
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?Langdon
Really just the major/minor tuple and comparators. I guess I could implement it myself, but was hoping for a readymade class.Alee
Yeah, I'm surprised there isn't one in Apache Commons or Google Guava (at least as far as I can see).Langdon
N
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

Nashville answered 22/10, 2014 at 20:55 Comment(0)
S
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

Spearwort answered 27/3, 2012 at 15:6 Comment(2)
But I am afraid it is just a string in the end.Spearwort
I ended up implementing my own Version tuple, but thanks for the links, I've been using them!Alee
H
0

When you're using the Spring framework, you can use org.springframework.data.util.Version. It has a constructor which exactly fits your piece of code:

Version myVersion = new Version(2, 1);
Himalayas answered 2/8 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.