blaisewang / img2latex-mathpix

Mathpix has changed their billing policy and no longer has free monthly API requests. This repo is now archived and will not receive any updates for the foreseeable future.
Apache License 2.0
1.39k stars 209 forks source link

[Bug] Bash script does not execute JDK 11 but Gradle does #74

Closed hmf closed 4 years ago

hmf commented 4 years ago

Describe the bug I have changed the Gradle script to execute the application with the KDK 11 (LTS version). The changes can be found in my fork. They include a correction in the detection of the OS that was not working correctly (tested in Linux).

When I execute the application directly from the Gradle in the IDE, it works fine. However when I execute the bash script I get the following error:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: entry/Main has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
...
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)

To Reproduce Steps to reproduce the behavior:

  1. Set the active java version to JDK 11
  2. Clone the project
  3. Build and run via Gradle - application works.
  4. Go to the directory img2latex-mathpix/build/install/Image2LaTeX/bin
  5. Execute the script ./Image2LaTeX

Expected behavior I expect the application should execute us8ing the bash script as it does in Gradle.

Screenshots

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: entry/Main has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)

Desktop (please complete the following information):

Additional context I cannot figure out how the class is compiled in a different version of JDK seeing as it is set in the Gradle script.

github-actions[bot] commented 4 years ago

[Auto response] Looks like this is your first issue. I will look into it as soon as possible.

blaisewang commented 4 years ago

Probably you need to change the sourceCompatibility, targetCompatibility, and javafx version to 11 in the build.gradle file

hmf commented 4 years ago

@blaisewang My apologies but I was having problems pushing the changes. I have already changed the JDK version here. As I said, in Gradle it works but the installscript fails.

Please note that the OS detection has bugs in your master. If you like, I can make a pull request.

blaisewang commented 4 years ago

@hmf I reviewed your code and figured out what might be wrong. This project was originally developed with JDK 11 since last year. So, using JDK 11 should not be a problem here. The problem is that you didn't modify the jdk_setup.sh script. The JDK you initially downloaded inside the jdk/ folder is actually JDK 14.

blaisewang commented 4 years ago

To build with JDK 11, you need to modify 19 to 21 lines of scripts/jdk_setup.sh to

wget -nc -O $LINUX_JDK_FILE https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10/OpenJDK11U-jdk_x64_linux_hotspot_11.0.6_10.tar.gz
wget -nc -O $MACOS_JDK_FILE https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10/OpenJDK11U-jdk_x64_mac_hotspot_11.0.6_10.tar.gz
wget -nc -O $WINDOWS_JRE_FILE https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10/OpenJDK11U-jdk_x64_windows_hotspot_11.0.6_10.zip

and re-download the JDK 11 to build.

blaisewang commented 4 years ago

The build process for this software is not building three versions on three platforms. The software was built in Ubuntu with Travis CI. The org.gradle.internal.os.OperatingSystem couldn't use here as we are not building Windows version on a Windows PC.

21 - 30 lines of .travis.yml script explains how to do the cross-platform build. The -Plinux parameter is passed with ./gradlew runtimeZip, so the project.hasProperty("linux") is true. So does -Pwindows for project.hasProperty("windows") to be true.

The OperatingSystem.current().isWindows() part inside runtime is redundant as launch4j is used to build Windows version software.

I don't think it's a good idea to simply set javafx - version to ${compileJava.targetCompatibility}. There are minor JavaFX version like 11.0.2. The code is compatible with JDK 11, but using JavaFX's latest version such as 11.0.2 is always good practice as a minor version comes with bug fixes and security improvements.

blaisewang commented 4 years ago

I am using a mac so I put -Pmacos as the default situation to build with ./gradlew runtimeZip. You can use ./gradlew -Plinux runtimeZip to build the Linux version with JDK 11 if you set up JDK correctly inside jdk folder.

hmf commented 4 years ago

@blaisewang Thanks for the heads-up. I will make the changes to the script and run Gradle via command line as you indicated above. Maybe these instrcuction could be aded to the documentation.

blaisewang commented 4 years ago

@hmf Haven't thought anyone would concern about the build process. I was hoping people would contribute to the functionality. Definitely will write a contribution / develop guideline if I have a spare weekend in the future.