source: main/trunk/search4j/DisplayJavaVersion.java@ 36214

Last change on this file since 36214 was 35457, checked in by davidb, 3 years ago

Addition of java-based solution to more cleanly determine Java version and bitness, rather than relying of it's 'version' minus argument and inspecting with 'file' the 'java' program. This commit for Unix OS. A later phase of work will be the updated win32.mak file for Windows. Then a final phase of work will be for the 'search4j' source code to be tied in with the generated jar files

File size: 1.4 KB
Line 
1class DisplayJavaVersion
2{
3 public static void main(String args[])
4 {
5 boolean verbose = false;
6
7 if (args.length == 1) {
8 String arg0 = args[0];
9
10 if (arg0.equals("-v") || arg0.equals("-verbose") || arg0.equals("--verbose")) {
11 verbose = true;
12 }
13 }
14
15 // Adapted from:
16 // https://stackoverflow.com/questions/2591083/getting-java-version-at-runtime
17
18 String era, major, minor, update, build;
19
20 // 'java.version' property returns:
21 // era.major.minor
22 // 'java.runtime.version' returns:
23 // era.major.minor_update-build
24
25 // The simpler case can be deal with using:
26 // String[] javaVersionElements = System.getProperty("java.version").split("\\.");
27 //
28 // However, as search4j.cpp has already been written assuming that version information
29 // includes update (but not build number) details, then do the following:
30 //
31 String[] javaVersionElements = System.getProperty("java.runtime.version").split("\\.|_|-b");
32
33 era = javaVersionElements[0];
34 major = javaVersionElements[1];
35 minor = javaVersionElements[2];
36 update = javaVersionElements[3];
37 build = javaVersionElements[4]; // (unused)
38
39
40 // Testing bitness of JVM
41 // https://www.baeldung.com/java-detect-jvm-64-or-32-bit
42 //boolean is_64bit = com.sun.jna.Platform.is64Bit();
43
44 String version_str = era+"."+major+"."+minor+"_"+update;
45
46 if (verbose) {
47 System.out.println("Version: " + version_str);
48 }
49 else {
50 System.out.println(version_str);
51 }
52 }
53}
54
Note: See TracBrowser for help on using the repository browser.