Travis says jre is ver 11 but still won't run JAR of class file ver 55

i have Python application wired up to a Travis build. After the unit test 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)

I want to check instance:

$ 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. is there a way I can change this in my .travis.yml file?

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/solar/LPT/myApp.jar ./tests/LPT/input.json 

thank you,
solarultima

Hey @SolarUltima,

If you read the manpage on sudo you’ll find that the default policies generally clear a lot of environment variables for security reasons, (this happens automatically) and while you’re building your application and running your java -version check with normal permissions, (without chown/chmod) you’re using sudo java to actually have it in runtime. You may be getting a different PATH and/or JAVA_HOME in the two environments.

See if that doesn’t help, if it doesn’t post back and I’d like to see some more log files.

Thank you,

Montana Mendy

1 Like
Imprint