I\'m compiling a project in Eclipse using m2eclipse. I set the JDK path in Eclipse like this:
Windows-->preferences-->installed jres--> jdk1.7.xx p
Go to windows -> Preferences -> Java -> Installed JREs
may be jre is already added
click on Add -> Standard VM -> Next -> Directory
and browse for the JDK
in my case path was C:\Program Files\Java\jdk1.8.0_111
then Click on finish.
you will see window like this
select JDK -> Apply -> Ok
And You are done.
There are several options to specify.
Steps: Right on project in project explorer Go to Run-> Run Configuration -> Click Maven Build -> Click on your build config/or create a new config. You will see the window as the given snapshot below, click on JRE tab there.
You see you have 3 options 1) Workspace Default JRE 2)Execution Environment 3)Alternate JRE 1) Workspace Default JRE is set from 'Window' menu on the top -> Preferences -> Java -> Installed JREs -Here you can add your jdk 2) Execution Environment jdk can be set in pom.xml as mentioned by @ksnortum
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.7.0_45\bin\javac.exe</executable>
</configuration>
</plugin>
</plugins>
3) Alternate JRE can be used to select a jdk from your directory
For me, nothing worked until I made this change to my pom.xml:
<build>
...
<plugins>
...
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.7.0_45\bin\javac.exe</executable>
</configuration>
</plugin>
</plugins>
</build>
Other Notes
I could see that m2e was executing in a JRE, not the JDK. Nothing I did changed this, including adding this to the eclipse.ini:
-vm
C:\Program Files\Java\jdk1.7.0_45\bin\javaw.exe
In the end I never got m2e to execute in a JDK, but setting the Java compiler explicitly (as above) did the trick.
For me, it is exactly what the maven of eclipse complains
So, I press Edit
button and change path to the JDK Folder, then clean project and everything starts to work
I got a solution.
The most common solution for this problem is to change jdk location as my Installed JREs instead of the JRE location but that did not solve my problem this one time.
So I did the below to solve the problem. Expand the Installed JREs tab and you will find a Execution environments tab.
Click on your favourite execution environment. In my case it was JAVASE-1.8. There it shows 2 options. JDK and JRE. Select JDK there and the problem is solved.
In addition to answer above, I could say that just try to run Maven from the terminal (outside of Eclipse). In this way, if it builds from outside but not in Eclipse, you can understand that the problem should be in Eclipse.