Last change
on this file since 15224 was 15224, checked in by ak19, 16 years ago |
Java executable for checking the version of Java that's running against a required minimum version
|
-
Property svn:executable
set to
*
|
File size:
1.4 KB
|
Rev | Line | |
---|
[15224] | 1 |
|
---|
| 2 | public class CheckJavaVersion {
|
---|
| 3 | static final String MINIMUM_VERSION_PREFIX = "1.4";
|
---|
| 4 |
|
---|
| 5 | /**
|
---|
| 6 | * @param args, arg[0] is the minium version of Java required
|
---|
| 7 | * to run the program. arg[1] is the name of the program.
|
---|
| 8 | * If arg[1] is left out, then no distinct program name is
|
---|
| 9 | * mentioned. If arg[0] is left out as well, then Greenstone3's
|
---|
| 10 | * minimum default version of 1.4.x is assumed.
|
---|
| 11 | * The program exits with -1 if the Java version being used is
|
---|
| 12 | * incompatible and with 0 if it is acceptable.
|
---|
| 13 | */
|
---|
| 14 | public static void main(String[] args) {
|
---|
| 15 | String minimumVersion = MINIMUM_VERSION_PREFIX;
|
---|
| 16 | String programName = "this program";
|
---|
| 17 | // the version of java that's in use
|
---|
| 18 | String installedJavaVersion = System.getProperty("java.version");
|
---|
| 19 |
|
---|
| 20 | if(args.length > 0) {
|
---|
| 21 | minimumVersion = args[0];
|
---|
| 22 | }
|
---|
| 23 | if(args.length > 1) {
|
---|
| 24 | programName = args[1];
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | System.out.println("\nChecking for a compatible Java version..."
|
---|
| 28 | + "\nLooking for minimum version " + minimumVersion + ".x");
|
---|
| 29 |
|
---|
| 30 | if(installedJavaVersion.compareTo(minimumVersion) < 0) {
|
---|
| 31 | System.out.println(
|
---|
| 32 | "The current Java version "
|
---|
| 33 | + installedJavaVersion
|
---|
| 34 | + " is insufficient to run "
|
---|
| 35 | + programName
|
---|
| 36 | );
|
---|
| 37 | System.exit(-1);
|
---|
| 38 | } else {
|
---|
| 39 | System.out.println("Found compatible Java version "
|
---|
| 40 | + installedJavaVersion);
|
---|
| 41 | System.exit(0);
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.