Find linux distribution name from java

We are writing a small library in java that should collect information from the base system. We can read most of the material from the properties of the system in java, but we cannot find the right way to extract the distribution name when working on Linux. Call

System.getProperty("os.name"); 

return "Linux" (which we also compile), but we are looking for a way to get, for example. "Ubuntu". We need this solution in java and would like not to parse / etc / release

+5
source share
3 answers

To do this reliably and definitely impossible, the best I can offer is to output the output "uname -a" and use it.

Note. This is not a Java restriction — there is no simple (and accurate) means of identifying a distribution.

+7
source

You can try calling lsb_release -i , but this is not guaranteed.

+9
source

I usually use the following command:

  cat / etc / issue

Reading this file in Java should be fairly simple. The question is whether this file is for every (or at least most) Linux distributions. I found it wherever I needed it, although it was not very often needed.

+3
source

Source: https://habr.com/ru/post/914525/


All Articles