Maven pointing to JRE instead of jdk
- Jay
- 2013-07-12 17:20
- 5
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?
5 Answers
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.
maven java_home is not defined correctly, Maven, JAVA_HOME is not defined correctly on Mac OSX. Apple recommends to set JAVA_HOME to “ /usr/libexec/java_home “, for example : But, when execute the Maven command, it prompts following error messages : $ mvn -version Error: JAVA_HOME is not defined correctly. We cannot execute /usr/libexec/java_home/bin/java. Maven, JAVA_HOME is not defined correctly on Mac OSX. Apple recommends to set JAVA_HOME to “ /usr/libexec/java_home “, for example : But, when execute the Maven command, it prompts following error messages : $ mvn -version Error: JAVA_HOME is not defined correctly. We cannot execute /usr/libexec/java_home/bin/java.
Vijay Nandwana
2017-03-06 06:42
Windows CMD don't refresh environment variables and you need run new instance for applying new environment setting and refresh new variable JAVA_HOME.
this path is not pointing to a jdk., Before running any goals, Maven checks for the existence of the java command in the path specified by JAVA_HOME or by asking the OS for a default JDK installation. If the executable is not found, Maven terminates with the error. Here is the mvn executable check for Linux (Apache Maven v3.5.4): if [ -z "$JAVA_HOME" ] ; then Before running any goals, Maven checks for the existence of the java command in the path specified by JAVA_HOME or by asking the OS for a default JDK installation. If the executable is not found, Maven terminates with the error. Here is the mvn executable check for Linux (Apache Maven v3.5.4): if [ -z "$JAVA_HOME" ] ; then
r4ge
2015-09-01 09:27
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.
point maven to jdk, As in many other cases with Maven, it's recommended to set up meaningful system-wide settings – in this case, we'll change the value of the JAVA_HOME variable as described in section 5 to point to the JDK instead of the JRE. However, if we can't set up defaults for whatever reason, we can still override the settings on the project level. As in many other cases with Maven, it's recommended to set up meaningful system-wide settings – in this case, we'll change the value of the JAVA_HOME variable as described in section 5 to point to the JDK instead of the JRE. However, if we can't set up defaults for whatever reason, we can still override the settings on the project level.
Navneet Agarwal
2017-10-23 09:20
You can modify it on this window:
nb: java_home should point to a jdk not a jre jenkins, The JAVA_HOME environment variable is not defined correctly This environment variable is needed to run this program NB: JAVA_HOME should point to a JDK, not a JRE 3. JDK or JRE The JAVA_HOME environment variable is not defined correctly This environment variable is needed to run this program NB: JAVA_HOME should point to a JDK, not a JRE 3. JDK or JRE
yasin
2019-02-08 02:08
From the Maven Properties Guide:
java.home
property is not the same thing as JAVA_HOME environment setting. It is actually dynamic property showing you which JRE is running your code.Try setting the java.home property correctly and see if it works.
JAVA_HOME should point to a JDK not a JRE, For this reason, an mvn compile command would fail – as we'll see in the next subsection. 3.1. Compilation Failure Because of JRE Instead of This maven exception occurs when your Window/Unix environment variable for JAVA_HOME and PATH are pointing to JRE instead of JDK.
Juned Ahsan
2013-07-13 00:00