1

I had not developed Java in 10 years and needed to quickly compile a plugin project written with Java 8 features. I downloaded the latest JDK (AdoptOpenJDK 16) and installed it on my MacOS development machine.

Looking at the POM file for the project, I saw these two settings:

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

and read that these settings would tip the compiler that the code was written with Java 8 features and the compiled classes need to be compatible with the 1.8 JVM.

I followed the developer instructions yet encountered errors:

Upon initial build, the following error would stop the build :

[ERROR] import: Entry[import  from realm ClassRealm[project>org.github.flytreeleft:nexus3-keycloak-plugin:0.5.0-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]
[ERROR] 
[ERROR] -----------------------------------------------------
[ERROR] : begin 0, end 3, length 2
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

Similar people encountered the same issue on other projects. Ultimately I used a workaround that was suggested to skip the maven Enforcer to get past this error.

Upon rebuild, the project and would fail with about 90 compile errors in various files. The messages would say something similar to:

String cannot be resolved to a type

Which led me to this SO questions that had a similar error ... but no good answers.

How do I get this project to build?

Taterhead
  • 4,845
  • 2
  • 23
  • 35

1 Answers1

0

The solution is install the Java 8 JDK(LTS) and build with that.

First, I removed the latest JDK from my mac using these instructions, but in my case I had to use the appropriate directory:

sudo rm -rf /Library/Java/JavaVirtualMachines/openjdk-16.jdk

Second, go to:

https://adoptopenjdk.net/

and download and install the OpenJDK 8 (LTS). This will install the correct version and point the JAVA_HOME path to the correct location.

Once this was installed, I ran the build and the plugin compiled without error.

Alternatively, you can leave both installed and point your JAVA_HOME to the Java 8 LTS version with the following command:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_282`

the version string was found when I ran:

/usr/libexec/java_home -V          
Matching Java Virtual Machines (2):
    16 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 16" 
/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home
    1.8.0_282 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" 
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
Taterhead
  • 4,845
  • 2
  • 23
  • 35