Why am I getting 'Cannot invoke java.lang.Class.isInterface()' error during Vaadin 24 packaging in production mode?

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

Why am I getting 'Cannot invoke java.lang.Class.isInterface()' error during Vaadin 24 packaging in production mode?

问题

Vaadin 24 - 生产模式开启:在打包时出现 build-frontend 错误 / 无法调用 "java.lang.Class.isInterface()"

当使用 spring-boot:run 启动应用程序时,应用程序运行良好,但无法实现打包目标。

在 build-frontend 阶段显示以下错误:

[ERROR] 

POM 非常基本,具有以下配置:

        <java.version>17</java.version>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <vaadin.version>24.0.5</vaadin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

使用 JDK17 执行目标

错误仅在生产配置下显示。在其他配置下工作正常。
我在早期的 Vaadin 版本上找到了相同的错误报告,通过添加 --enable-preview 解决,但在此处使用 JDK17 / Vaadin24 时不起作用。

英文:

Vaadin 24 - Production mode on : Error on build-frontend when packaging / Cannot invoke "java.lang.Class.isInterface()"

While application is running well when started with spring-boot:run, we cannot achieve package goal.

Following error is showing on build-frontend phase :

[ERROR] Failed to execute goal com.vaadin:vaadin-maven-plugin:24.0.5:build-frontend (default-cli) on project myproj: Could not execute build-frontend goal: Error occured during goal execution: Cannot invoke &quot;java.lang.Class.isInterface()&quot; because the return value of &quot;org.reflections.Reflections.forClass(String, java.lang.ClassLoader[])&quot; is nullPlease run Maven with the -e switch (or Gradle with the --stacktrace switch), to learn the full stack trace. -&gt; [Help 1]
[ERROR] 

POM is quite basic, with cfg :

&lt;properties&gt;
        &lt;java.version&gt;17&lt;/java.version&gt;
        &lt;maven.compiler.source&gt;17&lt;/maven.compiler.source&gt;
        &lt;maven.compiler.target&gt;17&lt;/maven.compiler.target&gt;
        &lt;vaadin.version&gt;24.0.5&lt;/vaadin.version&gt;
        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
        &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
&lt;/properties&gt;

Executing goals with JDK17

Error only shows up with production profile. Works well without.
I found same error report on earlier Vaadin versions, solved adding --enable-preview, but not working here with JDK17 / Vaadin24

答案1

得分: 0

以下是翻译好的部分:

作为生产构建的一部分,会扫描类路径以查找带有某些注解的类,例如 @JsModule。这是为了能够创建最终应用程序中使用的 JavaScript 捆绑包。

基本上所做的工作包括:

  1. 为所有可用的类设置类加载器
  2. 使用 reflections 库查找带有 @JsModule 注解的类型
  3. 收集所有 @JsModule 注解的值并构建一个 JavaScript 捆绑包

第2步是出现问题的步骤,问题出在当找到具有特定注解的类后,尝试加载该类时无法加载它。

正如您提到的,一个问题可能是该类使用了预览特性,而您没有为生产构建启用预览特性。另一种情况在 https://github.com/vaadin/flow/issues/16577 中有描述,即包含了使用较新的 JDK 编译的依赖 JAR。

您可以通过在调试模式下在 IDE 中运行 Maven 目标并添加 NullPointerException 断点来找到有问题的类。然后可能会清楚实际的问题是什么。

英文:

As part of the production build, the classpath is scanned for classes for certain annotations such as @JsModule. This is to be able to create the JavaScript bundle used in the final application.

What is done is basically:

  1. Set up a class loader for all available classes
  2. Use the reflections library to find types annotated with e.g. @JsModule
  3. Gather the values from all @JsModule annotations and build a JavaScript bundle

Step 2 is the one that goes wrong here, and in the way that a class with a given annotation is found, but then when trying to load the class, it cannot be loaded.

As you mentioned, one problem might be that the class uses preview features and you have not enabled preview features for the production build. Another case described in https://github.com/vaadin/flow/issues/16577 is that a dependency jar compiled with a newer JDK was included.

You should be able to find the offending class by running the Maven target in an IDE in debug mode and adding a NullPointerException breakpoint. Then it might become clear what the actual problem is.

huangapple
  • 本文由 发表于 2023年5月25日 19:51:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331952.html
匿名

发表评论

匿名网友

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

确定