Find name of linux distro from java

我只是一个虾纸丫 提交于 2019-12-07 06:30:38

问题


We are writing a small library in java that needs to collect information from the underlying system. We are able to read most of the stuff from system properties in java, but we cannot seem to find the right way to extract the name of the distro when run on linux. The call

System.getProperty("os.name");

return "Linux" (which we also collect) but we are looking for a way to get e.g. "Ubuntu" as well. We need this solution in java and would like to not have to do some /etc/release parsing


回答1:


To do this reliably and accurately is impossible, the best I can suggest is to take the output of 'uname -a' and use that.

Note: This is not a Java limitation - there is simply no common (and accurate) means of identifying a distribution.




回答2:


You can try invoking lsb_release -i, but this is not guaranteed to work.




回答3:


I usually use the following command:

cat /etc/issue

Reading this file in Java should be quite easy. The question is whether this file is on every (or at least majority) of Linux distributions. I found it everywhere I needed it, though, it was not needed very frequently.



来源:https://stackoverflow.com/questions/4334426/find-name-of-linux-distro-from-java

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