'Maven pointing to JRE instead of jdk
I've been working with a co-worker on a problem I have been experiencing on a new project I just joined. Long story short, maven isn't building my .war file correctly. When I give my co-worker my war file, he experiences the same problem I have, and when he gives me his compiled .war file, everything works. We are both working with the same source. So, I am trying to get maven setup correctly (the same as his), we both have the same version of maven now. However, I think maven is looking at the java_home incorrectly.
when I do an mvn -version command, I get the following:
C:\java\KME_workspace\CU-KME>mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
Maven home: C:\java\tools\apache-maven-3.0.4
Java version: 1.6.0_45, vendor: Sun Microsystems Inc.
Java home: C:\java\jdks\jdk1.6.0_45\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
My system's JAVA_HOME variable is set correctly to C:\java\jdks\jdk1.6.0_45.
Anyone know my maven is looking at the jre, and how do I set it correctly back to the JDK? It's possible I am looking at the problem in correctly too, so if you have any ideas, that would be great.
Thanks.
As some noted, the JRE reference in the java home in the maven version was a red herring rabbit hole on my part. Upon further testing I have some new interesting information. I am running maven commands directly from the command line. I check out code from our svn repository with eclipse, and try to run a maven package on that code, and the .war doesn't build correctly. However, if I do a team export in eclipse to a new directory, and the run the maven package on that, it builds the .war fine and works perfectly. As I understand it, the team export in eclipse removes all the subversion files in the exported directory. Anyone have any ideas on how to solve this?
Solution 1:[1]
In Eclipse, Window>Preferences>Java>Installed JREs> make sure jdk is present and selected.
If jdk and jre both are present, then delete jre from Installed JREs.
Solution 2:[2]
You can replace the environment from jre to jdk in Eclipse IDE as follows if it also shows compiler unavailable :
- (right-click) your_project_name > Build Path > Configure Build Path > Libraries > (double-click) JRE System Libraries > Alternate Jre : jdk 1.8 >ok
- Then from Installed JRES option in Libraries select jdk 1.8
- Project > Clean
- Maven > Update
Solution 3:[3]
Windows CMD don't refresh environment variables and you need run new instance for applying new environment setting and refresh new variable JAVA_HOME.
Solution 4:[4]
Once you have the JDK installation path:
- Right-click the My Computer icon on your desktop and select Properties.
- Click the Advanced tab.
- Click the Environment Variables button.
- Under System Variables, click New.
- Enter the variable name as JAVA_HOME.
- Enter the variable value (one of the paths mentioned above) as the installation path for the Java Development Kit.
- Click OK.
- Click Apply Changes.
You might need to restart windows.
This worked for me.
Solution 5:[5]
Solution 6:[6]
This error also occurs, if you have variable named as javapath. Try to delete it, if you've already specified e.g. like JAVA_HOME -> "C:\Program Files\Java\jdk1.8.0_171"
and then in Path -> "%JAVA_HOME%\bin"
Solution 7:[7]
In my test, you only need to make sure the Java home output of mvn -version be the jre in your jdk home, That's the only way make maven work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vijay Nandwana |
| Solution 2 | Gadhia Reema |
| Solution 3 | r4ge |
| Solution 4 | Grimthorr |
| Solution 5 | yasin |
| Solution 6 | |
| Solution 7 | Nerd |

