프로그램에서 JVM 버전을 찾는 방법은 무엇입니까? 싶은 샘플 Java 파일을

클래스가 실행중인 JVM 버전을 알고 싶은 샘플 Java 파일을 작성하고 싶습니다. 방법이 있습니까?



답변

System.getProperty("java.version") 필요한 것을 반환합니다.

원하는 경우 JMX를 사용할 수도 있습니다.

ManagementFactory.getRuntimeMXBean().getVmVersion()


답변

그것은 보인다 java.specification.version직업에 가장 적합한 .

EG

java.specification.version  1.6
java.version    1.6.0_23
java.vm.version 19.0-b09
java.runtime.version    1.6.0_23-b05

답변

사용하다:

System.getProperty("java.version");

어디 java.version현재의 Java 버전에 관련된 다른 많은 시스템 속성 중 하나를 교체 할 수 있습니다. 다음은 그 테이블입니다.

 Property                        Value (OpenJDK 12)                        Value (Oracle JRE 8u201)                Value (Sun JRE 5u22)                                 Description
------------------------------- ----------------------------------------- --------------------------------------- ---------------------------------------------------- ---------------------------------------------------------------------------------------------------------------
 java.version                    "12"                                      "1.8.0_201"                             "1.5.0_22"                                           Java Runtime Environment version, which may be interpreted as a Runtime.Version
 java.version.date               "2019-03-19"                              null                                    null                                                 Java Runtime Environment version date, in ISO-8601 YYYY-MM-DD format, which may be interpreted as a LocalDate
 java.vendor                     "Oracle Corporation"                      "Oracle Corporation"                    "Sun Microsystems Inc."                              Java Runtime Environment vendor
 java.vendor.version             null                                      null                                    null                                                 Java vendor version
 java.vendor.url                 "https://java.oracle.com/"                "http://java.oracle.com/"               "http://java.sun.com/"                               Java vendor URL
 java.vendor.url.bug             "https://bugreport.java.com/bugreport/"   "http://bugreport.sun.com/bugreport/"   "http://java.sun.com/cgi-bin/bugreport.cgi"          Undocumented
 java.specification.name         "Java Platform API Specification"         "Java Platform API Specification"       "Java Platform API Specification"                    Java Runtime Environment specification name
 java.specification.vendor       "Oracle Corporation"                      "Oracle Corporation"                    "Sun Microsystems Inc."                              Java Runtime Environment specification vendor
 java.specification.version      "12"                                      "1.8"                                   "1.5"                                                Java Runtime Environment specification version, whose value is the feature element of the runtime version
 java.vm.name                    "OpenJDK 64-Bit Server VM"                "Java HotSpot(TM) 64-Bit Server VM"     "Java HotSpot(TM) 64-Bit Server VM"                  Java Virtual Machine implementation name
 java.vm.vendor                  "Oracle Corporation"                      "Oracle Corporation"                    "Sun Microsystems Inc."                              Java Virtual Machine implementation vendor
 java.vm.version                 "12+33"                                   "25.201-b09"                            "1.5.0_22-b03"                                       Java Virtual Machine implementation version which may be interpreted as a Runtime.Version
 java.vm.info                    "mixed mode, sharing"                     "mixed mode"                            "mixed mode"                                         Undocumented
 java.vm.specification.name      "Java Virtual Machine Specification"      "Java Virtual Machine Specification"    "Java Virtual Machine Specification"                 Java Virtual Machine specification name
 java.vm.specification.vendor    "Oracle Corporation"                      "Oracle Corporation"                    "Sun Microsystems Inc."                              Java Virtual Machine specification vendor
 java.vm.specification.version   "12"                                      "1.8"                                   "1.0"                                                Java Virtual Machine specification version, whose value is the feature element of the runtime version
 java.runtime.name               "OpenJDK Runtime Environment"             "Java(TM) SE Runtime Environment"       "Java(TM) 2 Runtime Environment, Standard Edition"   Undocumented
 java.runtime.version            "12+33"                                   "1.8.0_201-b09"                         "1.5.0_22-b03"                                       Undocumented
 java.class.version              "56.0"                                    "52.0"                                  "49.0"                                               Java class format version number
 jdk.debug                       "release"                                 null                                    null                                                 Undocumented
 sun.java.launcher               "SUN_STANDARD"                            "SUN_STANDARD"                          "SUN_STANDARD"                                       Undocumented
 sun.management.compiler         "HotSpot 64-Bit Tiered Compilers"         "HotSpot 64-Bit Tiered Compilers"       "HotSpot 64-Bit Server Compiler"                     Undocumented

출처 :

  • java -XshowSettings:all -version다양한 JVM 버전 에 대한 출력입니다 .
  • Java API 참조 문서 System.getProperties()

답변

단순히 System.getProperty("java.version").


답변

java.version, java.specification.version및 사용 예 java.runtime.version: 런타임에서 Java 버전 가져 오기 .


답변

아래 자바 코드는 JVM현재 IDE에서 사용할 수있는 버전을 반환합니다.

List<VirtualMachineDescriptor> descriptors = VirtualMachine.list();
          for (VirtualMachineDescriptor descriptor : descriptors) {
              System.out.println("Found JVM: " + descriptor.displayName());
              try {
                  VirtualMachine vm = VirtualMachine.attach(descriptor);
                  String version = vm.getSystemProperties().getProperty("java.runtime.version");
                  System.out.println("   Runtime Version: " + version);

                   String connectorAddress = vm.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress");
                  if (connectorAddress == null) {

                      connectorAddress = vm.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress");
                  }

                  JMXServiceURL url = new JMXServiceURL(connectorAddress);
                  JMXConnector connector = JMXConnectorFactory.connect(url);
                  MBeanServerConnection mbs = connector.getMBeanServerConnection();

                  ObjectName threadName = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
                  Integer threadCount = (Integer)mbs.getAttribute(threadName, "ThreadCount");
                  System.out.println("    Thread count: " + threadCount);
              }
              catch (Exception e) {
                  // ...
              }

산출:

Found JVM: /home/.../STS IDE/sts-bundle/sts-3.7.2.RELEASE//plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar -os linux -ws gtk -arch x86_64 -showsplash -launcher /home/.../STS IDE/sts-bundle/sts-3.7.2.RELEASE/STS -name STS --launcher.library /home/.../STS IDE/sts-bundle/sts-3.7.2.RELEASE//plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.300.v20150602-1417/eclipse_1612.so -startup /home/.../STS IDE/sts-bundle/sts-3.7.2.RELEASE//plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar --launcher.overrideVmargs -exitdata 1ad000f -product org.springsource.sts.ide -vm /usr/bin/java -vmargs -Dosgi.requiredJavaVersion=1.7 -Xms40m -XX:MaxPermSize=256m -Xverify:none -Xmx1200m -jar /home/.../STS IDE/sts-bundle/sts-3.7.2.RELEASE//plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar
   Runtime Version: 1.8.0_91-b14
Found JVM: com.intellij.idea.Main
   Runtime Version: 1.8.0_91-b14
Found JVM: Test
   Runtime Version: 1.7.0_80-b15

답변

필요한 것에 따라 다른 답변이 도움이 될 수 있습니다.

제 경우에는 그렇지 않았습니다. IBM JDK의 “완전한”버전 정보를 찾고있었습니다.

따라서 “진짜”대답은 다음과 같을 수 있습니다. 모든 시스템 속성을 덤프 하고 원하는 것을 제공하는 속성이 있는지 확인하십시오.

나의 경우에는; IBM JDK가

속성 : java.fullversion

JRE 1.8.0 IBM J9 2.8 Linux amd64-64 압축 참조 20161013_322271 (JIT 사용, AOT 사용)

J9VM-R28_Java8_SR3_20161013_1635_B322271

JIT-tr.r14.java.green_20161011_125790

GC-R28_Java8_SR3_20161013_1635_B322271_CMPRSS J9CL-20161013_322271