Search code examples
javaruntime-errorjava-7code-snippetssfx

Fixing JRE error in Java code and recompiling application


I tried run on Windows 7 some old utility that depends on old JRE version.

I have last Java Runtime Environment 1.7.0_79 installed. When I attepmt to start application, I got an error:

"Sivus requires JRE 1.4 or later to run. You can download JRE from...etc"

Is there a workaround to resolve/fix this or something of that nature? Program main executable packed in SFX ZIP archive, I extracted files, and found Java file, which makes the check. There is a code:

  public static boolean checkJavaVersion(){
    boolean ok = false;
    String version = System.getProperty("java.version");

    if (version.indexOf("1.1") > -1) {
      ok = false;
    }
    else if (version.indexOf("1.2") > -1) {
      ok = false;
    }
    else if (version.indexOf("1.3") > -1) {
      ok = false;
    }
    else if (version.indexOf("1.4") > -1) {
      ok = true;
    }
    else if (version.indexOf("1.5") > -1) {
      ok = true;
    }

    return ok;
  }
  public static void main(String[] args) {
    boolean DEBUG = false;
    try {


    // check if JRE is over 1.4
    if (checkJavaVersion() == false){
      JOptionPane.showMessageDialog(
          null,
          "SiVuS requires JRE 1.4 (or later) to run.\n"
          +"You can download the latest JRE from java.sun.com",
          "Java Run Time Environment Error",
          JOptionPane.WARNING_MESSAGE);
      System.exit(1);
    }

How to correct this issue and recompile the application again? Will the application that relies on JRE 1.4 work with current JRE?


Solution

  • An example of how I'm doing patches like this.

    1. Fix code - you can add 1.6, 1.7, 1.8 to checkJavaVersion or remove this check at main method.
    2. Put fixed java file in folder that matches package
    3. Compile java file, for example:

      call "C:\Program Files (x86)\Java\jdk1.7.0_79\bin\javac.exe" C:\test\mypackage\MyClass.java -cp C:\test\My.jar -source 1.4 -target 1.4

    4. Get compiled class file and replace old file (backup it first)