Possible Duplicate:
Finding the version of OSX inside java
I want to check the current Mac OS X version my Java application is running on using Java code. Specifically, i want to know if this is Lion or not.
That way i can determine if to use a library or not.
From the Apple menu in the corner of your screen, choose About This Mac. You should see the macOS name, such as macOS Monterey or macOS Big Sur, followed by its version number. If you need to know the build number as well, click the version number to see it.
In macOS, the JDK installation path is /Library/Java/JavaVirtualMachines/jdk-10. jdk/Contents/Home . The root directory of the JDK software installation.
First, we need to change the current directory to /usr/libexec using the cd command. Once we are in the /usr/libexec directory, we execute the ./java_home command with -V that returns the versions and locations of the installed Java. Here is the output after running the command.
Use:
System.getProperty("os.name") // Yields "Mac OS X"
System.getProperty("os.version") // Yields "10.7.4" for me on Lion
You can look at the system property os.version
http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
Did you try the following:
System.getProperty("os.name");
You can find more details at "System Properties".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With