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

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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 Comments

But I am afraid it is just a string in the end.
I ended up implementing my own Version tuple, but thanks for the links, I've been using them!
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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.