构建Alfresco时出现错误"类文件版本错误55.0,应为52.0"

21

我使用Maven Alfresco原型生成了一个项目:

mvn archetype:generate -Dfilter=org.alfresco:

尝试构建时失败:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/Mehrdad/alfresco/alfresco-platform/src/main/java/com/mehr/alfresco/platformsample/HelloWorldWebScript.java:[20,49] cannot access org.springframework.extensions.webscripts.Cache
  bad class file: C:\Users\mehrdad.s\.m2\repository\org\alfresco\surf\spring-webscripts\7.9\spring-webscripts-7.9.jar(org/springframework/extensions/webscripts/Cache.class)
    class file has wrong version 55.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for AIO - SDK 4.0 1.0-SNAPSHOT:
[INFO]
[INFO] AIO - SDK 4.0 ...................................... SUCCESS [  1.063 s]
[INFO] Alfresco Platform/Repository JAR Module ............ FAILURE [01:54 min]
[INFO] Alfresco Share JAR Module .......................... SKIPPED
[INFO] Integration Tests Module ........................... SKIPPED
[INFO] Alfresco Platform/Repository Docker Module ......... SKIPPED
[INFO] Alfresco Share Docker Module ....................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:02 min
[INFO] Finished at: 2020-03-10T09:42:54+03:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project alfresco-platform: Compilation failure
[ERROR] /D:/Mehrdad/alfresco/alfresco-platform/src/main/java/com/mehr/alfresco/platformsample/HelloWorldWebScript.java:[20,49] cannot access org.springframework.extensions.webscripts.Cache
[ERROR]   bad class file: C:\Users\mehrdad.s\.m2\repository\org\alfresco\surf\spring-webscripts\7.9\spring-webscripts-7.9.jar(org/springframework/extensions/webscripts/Cache.class)
[ERROR]     class file has wrong version 55.0, should be 52.0
[ERROR]     Please remove or make sure it appears in the correct subdirectory of the classpath.

D:\Mehrdad\alfresco>java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)

D:\Mehrdad\alfresco>javac -version
javac 1.8.0_231

你看到了javajavac都是8。我不知道如何解决这个问题。

问题是什么?

6个回答

32
它抱怨说有些类文件是使用Java 11编译的(Java 55.0,Java类文件格式主要版本号列表?),而你尝试使用Java 8编译其余部分。
你应该将本地Java版本更新至至少Java 11,然后再尝试重新编译。

3

好的,我知道现在回答这个问题有点晚了,但如果对任何人有帮助的话。

所以问题是因为您有使用不同版本Java编译的jar文件。

这里,“Alfresco平台/仓库JAR模块”是在项目中与其余模块使用不同版本的Java编译的。

如果您在模块之间保持版本相似,则错误将消失。


1
好的,我知道回答这个问题有点晚。 但是永远不会太晚。
当一个API在JDK 11上编译,即主要.次要版本为55时,而你的源代码在JDK 8上时,就会出现这个问题。
我们可以用多种方式解决它。
  1. 如果是Maven项目,我们可以选择使用JDK 11或JDK 17
对于JDK 17
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>

或者

<java.version>17</java.version>

在使用JDK 11时

<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

或者

<java.version>11</java.version>

2. [Eclipse更改JRE](link1) 3. [Intellij更改JRE](link2)

0
根据您的堆栈跟踪,spring-webscripts-7.9.jar 是使用 JDK 11 编译的。因此,您会收到这个错误(类文件版本错误,应为 52.0,而不是 55.0)。

build version

解决方法: 由于您的系统是Java 8版本,将spring-webscripts-7.9更改为spring-webscripts.7.2。无需升级Java 8到Java 11。

在您的pom.xml文件中添加以下依赖项

<!-- https://mvnrepository.com/artifact/org.alfresco.surf/spring-webscripts -->
<dependency>
    <groupId>org.alfresco.surf</groupId>
    <artifactId>spring-webscripts</artifactId>
    <version>7.2</version>
</dependency>

希望这对你有所帮助。


0

我遇到了一个 pom.xml 依赖项版本引发错误的问题(java 和 javac 版本相同)。 解决方案是尝试其他版本的相同依赖项,通过逐个降级版本并进行尝试,最终找到了可编译的版本。 :)


0
如果从Eclipse运行(例如Maven命令),请确保在JRE选项卡下使用正确的JDK版本,以避免由不同JDK编译的JAR文件中出现任何错误。

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接