Determine linux version from java

∥☆過路亽.° 提交于 2019-12-01 15:59:11

问题


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.


回答1:


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



回答2:


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.




回答3:


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.




回答4:


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"




回答5:


/prov/version is a good start. /etc/issue might also be helpful.




回答6:


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.)



来源:https://stackoverflow.com/questions/1337329/determine-linux-version-from-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!