Getting Linux Distro from java
This code can help you:
String[] cmd = {
"/bin/sh", "-c", "cat /etc/*-release" };
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader bri = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String line = "";
while ((line = bri.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
UPDATE
It if you only need the version try with uname -a
UPDATE
Some linux distros contain the distro version in the /proc/version file. Here is an example to print them all from java without invoking any SO commands
//lists all the files ending with -release in the etc folder
File dir = new File("/etc/");
File fileList[] = new File[0];
if(dir.exists()){
fileList = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String filename) {
return filename.endsWith("-release");
}
});
}
//looks for the version file (not all linux distros)
File fileVersion = new File("/proc/version");
if(fileVersion.exists()){
fileList = Arrays.copyOf(fileList,fileList.length+1);
fileList[fileList.length-1] = fileVersion;
}
//prints all the version-related files
for (File f : fileList) {
try {
BufferedReader myReader = new BufferedReader(new FileReader(f));
String strLine = null;
while ((strLine = myReader.readLine()) != null) {
System.out.println(strLine);
}
myReader.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
How to check java version at linux (RedHat6)
To answer your question directly, you can use
rpm -qi java
OR
yum info "java"
For future Referenecs . You can try any of these commands.
rpm -qi "package_name_without_quotes"
It gives information of installed package. To display information about one or more packages (glob expressions are valid here as well), use the following command :
yum info "package_name_without quotes"
OR
yum list "package_name_without_quotes"
OR
yum --showduplicates list "package_name_without_quotes"
The yum info package_name command is similar to the rpm -q --info package_name command, but provides as additional information the ID of the Yum repository the RPM package is found in.
You can also query the Yum database for alternative and useful information about a package by using the following command :
yumdb info "package_name_without_quotes"
This command provides additional information about a package, including the check sum of the package (and algorithm used to produce it, such as SHA-256), the command given on the command line that was invoked to install the package (if any), and the reason that the package is installed on the system.
Determine linux version from java
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
How can I get Ubuntu version using Java?
You can run any terminal command (like lsb_release -a
) inside a Java class with
Runtime.getRuntime().exec("lsb_release -a");
And parse the output
EDIT: Clear solution
String[] args = new String[] {"/bin/bash", "-c", "lsb_release -r", "with", "args"};
Process proc = new ProcessBuilder(args).start();
Note: You need to use lsb_release -r to get only the version.
Where can i find which version of java my pc uses
None of the versions you've listed are Java 8 for linux. The closest is openjdk-7-jre-headless, but that's Java 7. The gcj is part of gcc
. To determine the version in Windows you can run,
java -version
or
java -fullversion
Linux version check Linux command or a Java code
Have you tried with?
cat /etc/*-release
cat /etc/redhat-release
or
cat /etc/issue
or
cat /proc/version
or even with
uname -a
Looking at Java documentation I see you can get few basic information about the operating system via System.getProperty(), I suppose you use Java Standard Edition 6.0. But very likely also other versions should return same infos.
- os.name Operating system name
- os.arch Operating system architecture
- os.version Operating system version
How to check java bit version on Linux?
Run java
with -d64
or -d32
specified, it will give you an error message if it doesn't support 64-bit or 32-bit respectively. Your JVM may support both.
Java version issue in linux server
(1)Use following command to detect installed java version
sudo update-alternatives --config java
(2)Select selection number & Enter
(3)Re-Check java version with
java -version
Related Topics
Wait Until Firestore Data Is Retrieved to Launch an Activity
Android Studio 3.1.3 Gradle Sync Error. Could Not Download Gradle-Core.Jar
How to Avoid Java.Net.Bindexception: Address Already in Use
How to Get Chromedriver Process Pid Using Java
Read_External_Storage Permission for Android
Change Unix Password with Java
How to Start Using and Developing on Ubuntu Linux
Cannot Run Program "Mvn" Error=2, No Such File or Directory
What's the Location of the Javafx Runtime Jar File, Jfxrt.Jar, on Linux
Tool for Creating a Java Daemon Service on Linux
Java Is Installed, in Listing, But Execution Produces "./Java: No Such File or Directory"
Java -Xbootclass Path Is No Longer a Supported Option
Is the Order of Values Retrieved from a Hashmap the Insertion Order