i am getting compilation error, when i build maven - spring

[ERROR] /D:/EclipseWorkSpace/Hibernate_Practice/src/main/java/com/dao/UserDaoImpl.java:[6,21] cannot access org.hibernate.Session
bad class file: C:\Users\Sreenivasulu.P.m2\repository\org\hibernate\orm\hibernate-core\6.1.1.Final\hibernate-core-6.1.1.Final.jar(org/hibernate/Session.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.

52 means JDK 1.8 and 55 means JDK11, further it means that you are trying to compile your project with mixed JDK11 and JDK8.
Three places where you need to set your JDK with the sam value:
Eclipse Java Build Path ( Installed JREs )
Eclipse Java Compiler
PC Terminal ( JAVA_HOME )
Also Hibernate 6 does not work well with Spring 5 due to the package name changes ( in 6 it's jakarta, in 5 it is javax ), so it would be wise to downgrade to Hibernate 5.
After these changes delete the content of your .m2 folder, right click on your project > Maven > Update.
Then you can run mvn clean install from your terminal.

Related

Intellij MavenWrapperDownloader.java: Can not resolve symbol error

Setup:
Intellij IDEA community edition 2020.2
Spring Bott starter parent: 2.3.5
Java 11
WRAPPER_VERSION: 0.5.6
mvn 2
Hi,
I googled a lot e.g. here but I just can't fix it.
I created a new mvn spring project with Intellij. When I commit the project I get errors detected by code analyses in class: MavenWrapperDownloader.java.
e.g. It reports:
Cannot resolve symbol String
I tried:
invalidate caches and restart
delete .idea folder and reimport
checked sdk setup
mvn reimport
mvn clean and then rebuild (while the build is always successful)
I'm pretty new to maven. I guess the scope of the mvn package might be wrong because the build process works as expected.
UPDATE:
I reinstallt my openjdk11. No success. Then I found out that my .mvn/wrapper dir is not set as source root. I know that was never the case in my other projects. As a trial I've set my .mvn folder as source root and now the MavenWrapperDownloader.java file is recognized as a java class and the compiler interprets the symbols. But now there is another error. It says I have to define a package name for that class because the class does not have one per default. It is pretty strange to me. I also tried to use another spring boot starter version but nothing changed
When I execute Analyze->inspect code I get the following:
I had the same problem and File -> Invalidate Caches/Restart fixed it - at least for now.
IntelliJ Ultimate 2020.3
Spring Boot Starter Parent 2.4.2
Java 15
Maven 4.0.0
Maven Wrapper 0.5.6
The easiest solution is to generate your project again with Spring Starter.
After you set up everything you need at pom file -> Generate -> Download it.
Open with your IDE and copy-paste all code sources which you have already written.

IntelliJ pulling in maven-enforcer-plugin without it being explicitly part of the pom.xml

When doing a build from IntelliJ I get the error saying
org.apache.maven.plugins.enforcer.RequireMavenVersion failed with message:
Detected Maven Version: 3.3.9 is not in the allowed range 3.6.0.
My maven Version is 3.3.9 and this is the one I want to stick to. I do recall when opening IntelliJ for the first time, going through a UI which asked me to specify a minimum and a maximum version for Maven and I did indeed specify 3.6 as a minimum. However I struggle to find the same settings at this point. Can someone point me to where IntelliJ's settings for Maven version boundaries are?
I'm using IntelliJ 2017.3.5
You can try this path
-> Menu > Preferences > Type: Maven or Go to Building, Execution: Maven > select your version - 3.3.9 from Maven home directory: dropwdown
Make sure you downloaded and set maven environment as global variables on your PC

Spring ROO build error: no tools.jar , jdk7, pom.xml

every pioneers,
I want to try to build Spring Roo 2.0.0.M2(http://projects.spring.io/spring-roo/) with its saying of STS 3.7.0 and JDK 1.7.0_45, and I couldn't find the solution even according the post on other sites or on " Builds failing after upgrading to Java7, Missing Tools.jar and bad class versions " .
The error messages on auto generated POM.xml are:
??????????????????????????????????????
You need to run build with JDK or have tools.jar on the classpath.If this occures during eclipse build make sure you
run eclipse under JDK as well (com.mysema.maven:apt-maven-plugin:1.1.3:process:default:generate-sources)
org.apache.maven.plugin.MojoExecutionException: You need to run build with JDK or have tools.jar on the
classpath.If this occures during eclipse build make sure you run eclipse under JDK as well at
com.mysema.maven.apt.AbstractProcessorMojo.execute(AbstractProcessorMojo.java:362) at
....
?????????????????????????????????????
Even I have tried: add JDK1.7.0_45 path but not JRE path in STS project, and even I added tools.jar directly in project build-paths, and even I use "mvn generate source" and add the generate jar into source path. The error about apt-maven-plugin:1.1.3 is still there.
Is there any person who can help? I will try to use old apt-maven-plugin latter.

How to update the version of Maven used by IntellijIdea

I try to open the Maven project in IntellijIdea. This project uses spark and scala. When I run:
mvn clean install -DskipTests
then it gives the error:
[ERROR] Failed to execute goal
org.scalastyle:scalastyle-maven-plugin:0.7.0:check (default) on
project spark-mllib_2.10: Failed during scalastyle execution: You have
50 Scalastyle violation(s)
I think that the problem is in the version of Maven. Indeed in IntellijIdea Settings I have the version Bundled (Maven 3) 3.0.5, while pom.xml defines <maven.version>3.3.3</maven.version>
If I run mvn -version in terminal, it points Maven 3.3.3
So, how can I update the version of Maven used by IntellijIdea?
Install the new version of maven (If not already installed)
Go to File -> Settings and use the search bar to find maven settings
Edit the Maven home directory setting so it points to the installation folder of the desired version
It may sometimes happen that after configuring maven in Intellij and changing as following it does not work by command build, so build it by Intellij maven tool.
Setting > Maven > Importer - select the JDK
Setting > Maven > Runner - select the JRE
After that, try to build by Intellij maven tool instead of Intellij console.

Hudson build error: LifecycleExecutionException Unable to locate the Javac Compiler in

I created a dynamic web project in eclipse for a web service with axis2. I then converted it into Maven project, I'm able to compile and generate war file in eclipse, but when i deploy it on server and try to build it with Hudson-3.0.0 it gives me following error:
mojoFailed org.apache.maven.plugins:maven-compiler-plugin:2.3.2(default-compile)
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project WebServices: Compilation failure
Unable to locate the Javac Compiler in:
C:\Program Files (x86)\Java\jre6..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
Please Let me know what's wrong with it!
I have exactly the same problem, ever since I upgraded Hudson from 2.2.1 to 3.0.1.
Both JAVA_HOME environment variable and JDK in hudson configuration point to JDK and not to JRE.
If I run mvn compile in the workspace directory of the job, everything works well.
Looks like the hudson cannot find java_home.
In hudson settings java.home property is set correctly ?
Does any other java projects builds successfully ?
Did you do what the exception said yet?
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
Sounds like you don't have Java installed. So install it.

Resources