Spring Boot application build failed - java

I am trying to build locally this repository https://github.com/spring-projects/spring-petclinic
I followed the steps from the repo but the build result looks like this:
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.757 s
[INFO] Finished at: 2023-01-23T15:27:08+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.1:build-info (default) on project spring-petclinic: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:3.0.1:build-info failed: Unable to load the mojo 'build-info' in the plugin 'org.springframework.boot:spring-boot-maven-plugin:3.0.1' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: org/springframework/boot/maven/BuildInfoMojo 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.
My Java version is:
$ java -version
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu218.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu218.04, mixed mode)
And Maven version is:
$ mvn -v
Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 11.0.17, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.10.102.1-microsoft-standard-wsl2", arch: "amd64", family: "unix"
I tried to run the steps from the repo, but that didn't worked for me.

Try Java 14 or above to handle this:
Java SE 14 (or JDK 14) is the version that handles class files with a version number of 61.0

class file version 61.0 = Java 17. If you are trying to run the project via your IDE, it will be using an independant java version from what's configured for your terminal's classpath.
The tutorial mentiones Intellij, so I'll assume that's what you're using. Go into File -> Project Structure and you will have your SDK and Language Level in there for that project, make sure they're the correct versions.

Related

Maven error: Unable to load cache item not working on vps but works locally

So I have been trying to compile my maven project on a VPS and made sure that all the versions of maven and jdk are the same as on my system. I even use the same system yet when I compile it on the VPS I get the error:
[ERROR] Error executing Maven.
[ERROR] java.lang.IllegalStateException: Unable to load cache item
[ERROR] Caused by: Unable to load cache item
[ERROR] Caused by: Could not initialize class com.google.inject.internal.cglib.core.$MethodWrapper
the output of mvn -v is:
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 17.0.1, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-17-oracle
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-97-generic", arch: "amd64", family: "unix"
output of java -version is:
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
The problem is that you maven version is too old, similar to this qustion.
Try updating maven manually.
If you have curl installed, run
curl -O https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.zip
in the directory that should contain maven at the end. Unzip it with
unzip apache-maven-3.8.6-bin.zip
There should now be a new directory called apache-maven-3.8.6. Now add apache-maven-3.8.6/bin to your PATH. If you don't know how to do this: add
export PATH="$PATH:YOURPATH/apache-maven-3.8.6/bin"
to ~/.profile. But remember to change YOURPATH to the path where the apache-maven-3.8.6 directory is located.
Your maven version and java version are not compatible. You have two options to follow.
1. Update maven version
For this may be you can follow steps mentioned in MrKleeblatt's answer above.
2. Change java version
In my case I had to follow this method as I was working in a legacy project.
Step 1: Select java version
sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode
Step 2: Set environment variables
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64

gradle Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'

I'm building ghidra according to the installation guide.
Everything goes fine Until I get here.
Once I call $ gradle buildGhidra I get the following error:
> Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'
This seems weird because I do have java 11:
$ java --version
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1, mixed mode, sharing)
What am I missing?
I got this problem when trying to build using gradle through Intellij.
In my case I had two JDK's JDK1.8 and JDK 11 installed and configured in Intellij.
For Gradle it was taking JDK1.8 as default JVM.
I solved the issue using below steps :
Open Intellij
Go to Preferences
Go to "Build, Execution, Deployment" -> "Build Tools" -> Gradle
Search for "Gradle JVM". Change it to desired JVM
Try to rebuild the app
Gradle uses the java distribution defined in your JAVA_HOME environment variable - it does not look at the java executable in your path. So make sure this variable points to a valid JDK 11 path. You can verify if it is set up correctly by running gradle --version, e.g.
$ echo %JAVA_HOME%
C:\Work\JDKs\jdk-11.0.8+10
$ gradle --version
------------------------------------------------------------
Gradle 6.6
------------------------------------------------------------
Build time: 2020-08-10 22:06:19 UTC
Revision: d119144684a0c301aea027b79857815659e431b9
Kotlin: 1.3.72
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM: 11.0.8 (AdoptOpenJDK 11.0.8+10)
OS: Windows 10 10.0 amd64
(Notice the JVM part above.)
Are you using an IDE? Make sure that in your Gradle settings, Gradle is using the same java version as your project, this can be easily configured in Intellij https://www.jetbrains.com/help/idea/gradle-jvm-selection.html#jdk_existing_project
It turns out that gradle was after all the one to blame.
Probably similar to this post, I upgraded to gradle-6.7.
Then, calling gradle-6.7 --version, without any JAVA_HOME change whatsoever, I got:
------------------------------------------------------------
Gradle 6.7-rc-3
------------------------------------------------------------
Build time: 2020-09-30 19:16:51 UTC
Revision: 836e96a80625c9c48b612e662e3b13bd2e2f4c3b
Kotlin: 1.3.72
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM: 11.0.8 (Ubuntu 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
OS: Linux 5.4.0-48-generic amd64
Which probably "proves" gradle is indeed the one to blame
Changing my agent label in the Jenkinsfile, to openjdk11 fixed this error for me.
agent {
label 'openjdk11'
}

maven takes Java 1.5 default even if JAVA_HOME is set to JDK11

I am using JDK 11 and my application has around 20 projects. Now I want my maven to pick JAVA_HOME instead of changing all pom.xml with maven-compiler-plugin or by properties.
I have set JAVA_HOME to JDK 11
Output of mvn -v
OpenJDK 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 19:21:28+0530)
Maven home: /home/krawler/apache-maven-3.0.5
Java version: 11.0.4, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-11-openjdk-11.0.4.11-0.el7_6.x86_64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.1.3.el7.x86_64", arch: "amd64", family: "unix"
But when I run mvn clean install I get below error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project mavenKwlCommonLibs: Compilation failure: Compilation failure:
[ERROR] error: Source option 5 is no longer supported. Use 6 or later.
[ERROR] error: Target option 1.5 is no longer supported. Use 1.6 or later.
There is a difference between the JDK you use and the Java version you compile for. You can very well compile for Java 8 with a JDK 11 (just one example).
You need to set
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
in your POM to the Java version you want to build for (see also https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html)
For Java 11, have also a look at https://stackoverflow.com/a/51586202/927493.

Failure executing javac, but could not parse the error:

Given the following:
> mvn clean compile
...
[ERROR] Failure executing javac, but could not parse the error:
/bin/sh: c:/progra~1/java/jdk1.6.0_24/bin/javac: No such file or directory
checked that my mvn and java versions were correct:
$mvn -version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T07:57:37-04:00)
Maven home: /Users/kevin/Downloads/apache-maven-3.3.3
Java version: 1.8.0_51, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.4", arch: "x86_64", family: "mac"
$java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Unsure of a problem with my brew-installed mvn, I removed it and downloaded mvn-...bin.zip from Apache. Then I set my PATH, verified that mvn -version and java -version spit out the same versions. But, I'm still having the same problem.
I looked at the top 3 (from search) StackOverflow results, but have not gotten any further:
Maven compilation error. Failure executing javac, but could not parse the error:javac: invalid flag: -s
Maven, Failure executing javac: Compilation failure
Compilation error: Failure executing javac, but could not parse the error
You should check your JAVA_HOME variable or pom.xml for this Windows-specific path: c:/progra~1/java/jdk1.6.0_24/bin/javac and change it to your real JDK installation path (/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre?).
I ran into similar issue when i started using a newer version of java.
In your case Maven is using java 6. Try setting JAVA_HOME environment variable to correct JDK version. I guess JAVA_HOME is pointing to jdk 1.6.

Maven Spring boot compilation error?

I am trying to compile a spring boot project with mvn package command but I am getting this error. I believe I have the JDK 1.7_55 installed.
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.144s
[INFO] Finished at: Fri May 16 11:57:18 EST 2014
[INFO] Final Memory: 8M/154M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project m
yproject: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Here is the output of the javac.
testspring>javac -version
javac 1.7.0_55
And here is the output of maven version.
..\testspring>mvn -v
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-20 00:51:28+1100)
Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.0.5\bin\..
Java version: 1.7.0_55, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jre7
Default locale: en_AU, platform encoding: Cp1252
OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "windows"
try the following
Go to
Windows -> Preferences -> Java -> Installed JREs
And check whether it is pointing to your JDK path, if not, click on edit button and put the path you configured your JAVA_HOME enviroment.
And
Go to
Window > Preferences > Java > Installed JREs > Execution Environments
Select JavaSE-1.6 or your required version , click the jdk checkbox on the right.
Then right click on your project in eclipse and select Mavan -> “update project configuration”
Try setting your JAVA_HOME to the location where you have your JDK installed, for example:
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Or with newer JDK:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/
I got the issue because my java is referred to JRE rather than JDk.
I was using spring tool suite.
go to windows->preferences->Java->installedJre's and verify if it's pointed to JRE or JDK
Right click on your project-> goto properties ->Select java build path
-> switch to Libraries -> there you have to change jre to jdk
I think this will solve your problem.

Categories