Quarkus CLI选择了错误的Java版本用于开发模式。

huangapple go评论102阅读模式
英文:

Quarkus CLI picks wrong Java version for dev mode

问题

Quarkus CLI 选择使用 Java 11 而不是 Java 17 的原因可能是默认设置或配置问题。您可以通过以下方式配置 Quarkus CLI 使用与 Maven 相同的 Java 版本:

  1. 在项目的 Quarkus 配置文件中设置 Java 版本: 检查您的 Quarkus 配置文件,通常是 src/main/resources/application.propertiessrc/main/resources/application.yml。确保其中的 quarkus.java.version 设置为 17。如果没有该设置,可以手动添加它。

  2. 检查系统环境变量: 确保您的系统环境变量中的 JAVA_HOME 指向 Java 17 的安装路径。这可以帮助 Quarkus CLI 使用正确的 Java 版本。

  3. 检查 Quarkus CLI 版本: 确保您正在使用的 Quarkus CLI 版本支持 Java 17。有时,较旧的 CLI 版本可能不支持新的 Java 版本,因此需要升级 CLI 到最新版本。

关于 Maven 命令和 Quarkus CLI 之间的区别,主要区别在于它们的用途和执行环境:

  • Maven 命令通常用于构建和管理项目依赖,它遵循项目的 Maven POM 文件中的配置。因此,当您使用 mvn compilemvn test 时,它们会按照 POM 文件中的设置来执行。这是为了确保项目的构建和测试与所需的 Java 版本一致。

  • Quarkus CLI 旨在支持 Quarkus 项目的开发和快速迭代。它可能有自己的默认设置,这可能会导致使用不同的 Java 版本。因此,在使用 Quarkus CLI 时,您需要确保它也配置为使用 Java 17。

请根据上述建议检查您的配置,以确保 Quarkus CLI 使用正确的 Java 版本。

英文:

In my Quarkus 3.1.1.Final application I am using Java 17, which is configured in the POM file.
Normally I use the Quarkus CLI and execute quarkus dev or quarkus test while developing.

After upgrading I noticed that these commands no longer work and give the following error:

  1. Exception in thread "main" java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: org/apache/camel/quarkus/core/devmode/CamelHotReplacementSetup has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
  2. at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:137)
  3. at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:62)
  4. Caused by: java.lang.UnsupportedClassVersionError: org/apache/camel/quarkus/core/devmode/CamelHotReplacementSetup has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
  5. at java.base/java.lang.ClassLoader.defineClass1(Native Method)
  6. at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
  7. at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:506)
  8. at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:466)
  9. at java.base/java.lang.Class.forName0(Native Method)
  10. at java.base/java.lang.Class.forName(Class.java:398)
  11. at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1210)
  12. at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1221)
  13. at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1265)
  14. at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1300)
  15. at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1385)
  16. at io.quarkus.deployment.dev.IsolatedTestModeMain.setupRuntimeCompilation(IsolatedTestModeMain.java:73)
  17. at io.quarkus.deployment.dev.IsolatedTestModeMain.accept(IsolatedTestModeMain.java:123)
  18. at io.quarkus.deployment.dev.IsolatedTestModeMain.accept(IsolatedTestModeMain.java:34)
  19. at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:138)
  20. at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:93)
  21. at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:131)

It seems that the Quarkus CLI uses Java 11 (55.0) for its execution, even though I have configured Java 17 (61.0).
I have verified my configuration using mvn clean verify, mvn compile quarkus:dev and mvn compile quarkus:test which all build successfully.
Also in IntelliJ I am able to run all tests or individual tests successfully using Java 17.
The application runs in a Java 17 based Docker container without any problems.
The problem here is that Quarkus CLI seems to choose a different Java version.

What is the reason Quarkus CLI choses Java 11 instead of Java 17?
How can I configure Quarkus CLI to use the same Java version as Maven?
Is there anything to learn about the difference between the Maven commands and Quarkus CLI?

答案1

得分: 2

以下是您要翻译的内容:

"CLI Homebrew packaging is using the following script to determine the java binary that will be executed:

  1. # OS specific support. $var _must_ be set to either true or false.
  2. cygwin=false;
  3. darwin=false;
  4. case "`uname`" in
  5. CYGWIN*) cygwin=true ;;
  6. Darwin*) darwin=true
  7. if [ -z "$JAVA_VERSION" ] ; then
  8. JAVA_VERSION="CurrentJDK"
  9. else
  10. echo "Using Java version: $JAVA_VERSION"
  11. fi
  12. if [ -z "$JAVA_HOME" ]; then
  13. if [ -x "/usr/libexec/java_home" ]; then
  14. JAVA_HOME=`/usr/libexec/java_home`
  15. else
  16. JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
  17. fi
  18. fi
  19. ;;
  20. esac
  21. if [ -z "$JAVA_HOME" ] ; then
  22. if [ -r /etc/gentoo-release ] ; then
  23. JAVA_HOME=`java-config --jre-home`
  24. fi
  25. fi
  26. # For Cygwin, ensure paths are in UNIX format before anything is touched
  27. if $cygwin ; then
  28. [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  29. [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  30. fi
  31. # If a specific java binary isn't specified search for the standard 'java' binary
  32. if [ -z "$JAVACMD" ] ; then
  33. if [ -n "$JAVA_HOME" ] ; then
  34. if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  35. # IBM's JDK on AIX uses strange locations for the executables
  36. JAVACMD="$JAVA_HOME/jre/sh/java"
  37. else
  38. JAVACMD="$JAVA_HOME/bin/java"
  39. fi
  40. else
  41. JAVACMD=`which java`
  42. fi
  43. fi

If you go through it with your OS in mind and checking the various paths, I think you should have your answer as to why the CLI is using a different JDK than the java from your $PATH than Maven is using.

It's very environment-dependent so it's hard to help more without having the environment at hand."

英文:

The CLI Homebrew packaging is using the following script to determine the java binary that will be executed:

  1. # OS specific support. $var _must_ be set to either true or false.
  2. cygwin=false;
  3. darwin=false;
  4. case "`uname`" in
  5. CYGWIN*) cygwin=true ;;
  6. Darwin*) darwin=true
  7. if [ -z "$JAVA_VERSION" ] ; then
  8. JAVA_VERSION="CurrentJDK"
  9. else
  10. echo "Using Java version: $JAVA_VERSION"
  11. fi
  12. if [ -z "$JAVA_HOME" ]; then
  13. if [ -x "/usr/libexec/java_home" ]; then
  14. JAVA_HOME=`/usr/libexec/java_home`
  15. else
  16. JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
  17. fi
  18. fi
  19. ;;
  20. esac
  21. if [ -z "$JAVA_HOME" ] ; then
  22. if [ -r /etc/gentoo-release ] ; then
  23. JAVA_HOME=`java-config --jre-home`
  24. fi
  25. fi
  26. # For Cygwin, ensure paths are in UNIX format before anything is touched
  27. if $cygwin ; then
  28. [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  29. [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  30. fi
  31. # If a specific java binary isn't specified search for the standard 'java' binary
  32. if [ -z "$JAVACMD" ] ; then
  33. if [ -n "$JAVA_HOME" ] ; then
  34. if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  35. # IBM's JDK on AIX uses strange locations for the executables
  36. JAVACMD="$JAVA_HOME/jre/sh/java"
  37. else
  38. JAVACMD="$JAVA_HOME/bin/java"
  39. fi
  40. else
  41. JAVACMD=`which java`
  42. fi
  43. fi

If you go through it with your OS in mind and checking the various paths, I think you should have your answer as to why the CLI is using a different JDK than the java from your $PATH than Maven is using.

It's very environment-dependent so it's hard to help more without having the environment at hand.

huangapple
  • 本文由 发表于 2023年6月8日 23:30:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76433481.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定