I'm wondering if there's a way to determine which version of Linux I'm running (ie differentiate between RHEL4, RHEL5) from within the JVM. I'm just looking for a consistent way to differentiate between the operating systems and their versions.
I do not believe there are any system properties you can look at that will give you that information. How about just executing a cat /proc/version
and parsing the output.
Which version of the distro you're running or which version of the Kernel? I know that Red Hat used to keep their version number in a file called /etc/redhat-release. I'm not sure for the other distro's. You can get the kernel version by doing a system call on "uname -r"
The JVM gives you some basic information about the operating system via
System.getProperty()
"os.name" // OS name
"os.arch" // OS architecture
"os.version" // OS version
As far as I know it doesn't offers distribution specific information. At least for debian distributions this information is stored in a file called
/etc/issue
So it may help reading any of the files where the different distros store this information.
If the System.getProperty(x) where x is "os.name", "os.arch", "os.version" doesn't work for you then you may have to resort to running a native process as suggested (cat /proc/version, or lsb_release, etc.)
You can also have a look at lsb_release
lsb_release -a
would give you something like:
cyril@merlin:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 8.10
Release: 8.10
Codename: intrepid