mirror of
https://gitee.com/arthas/arthas.git
synced 2024-12-02 04:08:34 +08:00
Use JavaVersionUtils to get java version.
This commit is contained in:
parent
33565a89c6
commit
07d2ebd5e9
@ -1,36 +1,43 @@
|
||||
package com.taobao.arthas.common;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hengyunabc 2018-11-21
|
||||
*
|
||||
*/
|
||||
public class JavaVersionUtils {
|
||||
private static final String javaVersionStr = System.getProperty("java.specification.version");
|
||||
private static final String versionPropName = "java.specification.version";
|
||||
private static final String javaVersionStr = System.getProperty(versionPropName);
|
||||
private static final float javaVersion = Float.parseFloat(javaVersionStr);
|
||||
|
||||
public static String javaVersionStr() {
|
||||
return javaVersionStr;
|
||||
}
|
||||
|
||||
public static String javaVersionStr(Properties props) {
|
||||
return (null != props) ? props.getProperty(versionPropName): null;
|
||||
}
|
||||
|
||||
public static float javaVersion() {
|
||||
return javaVersion;
|
||||
}
|
||||
|
||||
public static boolean isJava6() {
|
||||
return Float.toString(javaVersion).equals("1.6");
|
||||
return javaVersionStr.equals("1.6");
|
||||
}
|
||||
|
||||
public static boolean isJava7() {
|
||||
return Float.toString(javaVersion).equals("1.7");
|
||||
return javaVersionStr.equals("1.7");
|
||||
}
|
||||
|
||||
public static boolean isJava8() {
|
||||
return Float.toString(javaVersion).equals("1.8");
|
||||
return javaVersionStr.equals("1.8");
|
||||
}
|
||||
|
||||
public static boolean isJava9() {
|
||||
return Float.toString(javaVersion).equals("9");
|
||||
return javaVersionStr.equals("9");
|
||||
}
|
||||
|
||||
public static boolean isLessThanJava9() {
|
||||
|
@ -3,6 +3,7 @@ package com.taobao.arthas.core;
|
||||
import com.sun.tools.attach.VirtualMachine;
|
||||
import com.sun.tools.attach.VirtualMachineDescriptor;
|
||||
import com.taobao.arthas.common.AnsiLog;
|
||||
import com.taobao.arthas.common.JavaVersionUtils;
|
||||
import com.taobao.arthas.core.config.Configure;
|
||||
import com.taobao.middleware.cli.CLI;
|
||||
import com.taobao.middleware.cli.CLIs;
|
||||
@ -73,8 +74,8 @@ public class Arthas {
|
||||
}
|
||||
|
||||
Properties targetSystemProperties = virtualMachine.getSystemProperties();
|
||||
String targetJavaVersion = targetSystemProperties.getProperty("java.specification.version");
|
||||
String currentJavaVersion = System.getProperty("java.specification.version");
|
||||
String targetJavaVersion = JavaVersionUtils.javaVersionStr(targetSystemProperties);
|
||||
String currentJavaVersion = JavaVersionUtils.javaVersionStr();
|
||||
if (targetJavaVersion != null && currentJavaVersion != null) {
|
||||
if (!targetJavaVersion.equals(currentJavaVersion)) {
|
||||
AnsiLog.warn("Current VM java version: {} do not match target VM java version: {}, attach may fail.",
|
||||
|
Loading…
Reference in New Issue
Block a user