简体   繁体   中英

Travis CI says JRE is 11 but still won't run JAR of class file version 55

I have a Python application wired up to a Travis CI build. After the tests run, I need to spin up the application and then run a JAR file to complete testing. The JAR file was compiled with Java 11 and is of class file version 55. In my build, I get the following exception:

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/myApp/main/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:756)
    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:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)

EDIT : Added rest of exception

To check the Java version in the Travis instance, I have a java -version line that returns the following:

$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

So why is the exception acting like the Travis instance is running an earlier version of Java? I had this same problem locally and was able to fix it by changing my JRE from Java 8 to 11 and never had any problems after that. Is the java -version command not tell me the JRE version like I think it is? Is there a way I can change the JRE of the Travis instance by using the .travis.yml file?

If necessary, here's the relevant parts of .travis.yml :

after_script:
  - chmod +x ~/build.sh
  - chmod 777 ./tests/LPT/myApp.jar
  - bash ~/build.sh
  - java -version # output of this is shown in question
  - sudo java -jar ./tests/LPT/myApp.jar ./tests/LPT/input.json 
^ Last line triggers the exception shown in question

sudo 's default policies generally clear a lot of environment variables for security reasons, and while you're building your application and running your java -version check with normal permissions, you're using sudo java to actually run it. You may be getting a different PATH and/or JAVA_HOME in the two environments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM