OpenJDK Maven 编译出错: package jdk.nashorn.internal.runtime.logging does not exist

前言

  • OpenJDK 1.8.0
  • Maven 3.8.5
  • TencentOS Server 3.1

错误信息

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project tour-common: Compilation failure: Compilation failure: 
[ERROR] /opt/tour-common/src/main/java/com/tour/common/utils/ElasticSearchClientUtil.java:[6,44] package jdk.nashorn.internal.runtime.logging does not exist
[ERROR] /opt/tour-common/src/main/java/com/tour/common/utils/ElasticSearchClientUtil.java:[39,2] cannot find symbol
[ERROR]   symbol: class Logger
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn  -rf :tour-common

分析

缺少 jdk.nashorn.internal.runtime.logging

情况1

OpenJDK中没有nashorn.jar。
jdk.nashorn.internal.runtime.loggingnashorn.jar 中。

解决办法:安装jdk1.8,从jdk的安装目录中找到 nashorn.jar 拷贝到OpenJDK的对应位置。
nashorn.jar%JAVA_HOME%\jre\lib\ext目录。

情况2

JDK的高版本中移除了 nashorn.jar

解决办法:降低版本到jdk1.8。

maven 操作

查看maven使用哪个JDK

shell> mvn -v
Apache Maven 3.8.5 (Red Hat 3.8.5-3)
Maven home: /usr/share/maven
Java version: 17.0.7, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-17-openjdk-17.0.7.0.7-3.tl3.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.119-19-0009.11", arch: "amd64", family: "unix"

查看JAVA_HOME

shell> echo $JAVA_HOME

设置JAVA_HOME

参考这里。

临时设置JAVA_HOME

shell> export JAVA_HOME=/usr/lib/jvm/TencentKona-8.0.12-352

找到java安装目录

shell> which java
/usr/bin/java
shell> ll /usr/bin/java
lrwxrwxrwx 1 root root 22 Sep 21  2022 /usr/bin/java -> /etc/alternatives/java
shell> ll /etc/alternatives/java
lrwxrwxrwx 1 root root 48 Oct 31  2022 /etc/alternatives/java -> /usr/lib/jvm/TencentKona-8.0.12-352/jre/bin/java
shell> cd /usr/lib/jvm/TencentKona-8.0.12-352
shell> ll
total 51564
-r--r--r--  1 root root     1522 Oct 21  2022 ASSEMBLY_EXCEPTION
drwxr-xr-x  2 root root     4096 Oct 31  2022 bin
drwxr-xr-x  9 root root     4096 Oct 31  2022 demo
drwxr-xr-x  3 root root     4096 Oct 31  2022 include
drwxr-xr-x  4 root root     4096 Oct 31  2022 jre
drwxr-xr-x  3 root root     4096 Oct 31  2022 lib
-r--r--r--  1 root root    19274 Oct 21  2022 LICENSE
drwxr-xr-x  4 root root     4096 Oct 31  2022 man
-rw-r--r--  1 root root       84 Oct 21  2022 release
drwxr-xr-x 10 root root     4096 Oct 31  2022 sample
-rw-r--r--  1 root root 52581093 Oct 21  2022 src.zip
-r--r--r--  1 root root   157063 Oct 21  2022 THIRD_PARTY_README

TencentOS Server 3.1 自带OpenJDK

TencentOS Server 3.1 中带2个OpenJDK

  • openjdk version “1.8.0_352”
  • openjdk 17.0.7 2023-04-18 LTS

切换jdk

设置JAVA_HOME即可

其它

https://blog.csdn.net/wlopper/article/details/119676442
https://blog.csdn.net/qq_36135928/article/details/120190807
https://stackoverflow.com/questions/59126867/jdk-nashorn-internal-ir-annotations-does-not-exist

你可能感兴趣的:(java,error,maven,java,maven)