[英]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.我有一个连接到 Travis CI 构建的 Python 应用程序。 After the tests run, I need to spin up the application and then run a JAR file to complete testing.
测试运行后,我需要启动应用程序,然后运行 JAR 文件以完成测试。 The JAR file was compiled with Java 11 and is of class file version 55. In my build, I get the following exception:
JAR 文件是用 Java 11 编译的,类文件版本为 55。在我的构建中,我得到以下异常:
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:要检查 Travis 实例中的 Java 版本,我有一个
java -version
行,它返回以下内容:
$ 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?那么为什么异常表现得像 Travis 实例正在运行早期版本的 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.
我在本地遇到了同样的问题,并且能够通过将我的 JRE 从 Java 8 更改为 11 来修复它,此后再也没有出现任何问题。 Is the
java -version
command not tell me the JRE version like I think it is? java -version
命令是不是像我想的那样告诉我 JRE 版本? Is there a way I can change the JRE of the Travis instance by using the .travis.yml
file?有没有办法可以使用
.travis.yml
文件更改 Travis 实例的 JRE?
If necessary, here's the relevant parts of .travis.yml
:如有必要,这里是
.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.出于安全原因,
sudo
的默认策略通常会清除许多环境变量,并且当您构建应用程序并以正常权限运行java -version
检查时,您正在使用sudo java
来实际运行它。 You may be getting a different PATH
and/or JAVA_HOME
in the two environments.您可能会在这两种环境中获得不同的
PATH
和/或JAVA_HOME
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.