Maven pointing to JRE instead of jdk
Asked Answered
S

8

23

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?

Synge answered 12/7, 2013 at 17:20 Comment(12)
What is incorrect about your WAR file? Perhaps that will give us some hints. Also, just so you know running mvn --version on my Windows 7 box gives me the same output (except with Java 7) and my war files build fine.Cullin
I don't think maven is the source of your problem. Running mvn -version on my Linux box shows Java home as /usr/local/java/7u25/jre. What do you mean by "maven isn't building my war file correctly". Have you compared the two war files to see what's different?Countryandwestern
Maven (mvn) is a shell script; it's just telling you what jre it's using to actually do stuff. The output you post is exactly what it should be.Sall
Maven is correct -- it's using the jdk, as you can see from jdk1.6.0_45. What is the actual problem you are observing with your build?Farflung
Can you please confirm that your pom.xml and setting.xml files are the same?Gewirtz
pom.xml and settings.xml are both the same. Concerning the .war file not being compiled correctly, unfortunately no errors are thrown to tomcat logs, and the browser shows a generic "there was a problem" type error. And with everything pretty much being the same between our two systems, we are working under the presumptions my box isn't compiling the code correctly.Synge
you should maybe un-accept the accepted answer here as it is not related to the problem you're having...Forb
also, you should add what does ".war doesn't build correctly" actually mean, preferrably with a test case. It's really hard to have an answer without it.Forb
It's been a while since this question was asked, and it may be the case that you no longer work at wherever you ran into this, but could you fill in some more details? Do you remember what errors you were getting? What did you do to verify that it wasn't building correctly?Wozniak
There hasn't been any feedback, so like discussed in meta, I'm suggesting people to vote to close this as unclear as there is no way to answer the question as it stands. I cannot do that myself as I've already voted to close this before.Forb
Juned Ahsan was the answer I was looking for. It's been a while since I asked this so I forget some details.Synge
That can't be true as setting java.home property makes no sense, and like explained, it cannot be related to actual problem (whichever it may be).Forb
E
27

From the Maven Properties Guide:

${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example: ${java.home}../bin/java.exe

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.

Egoist answered 12/7, 2013 at 17:27 Comment(9)
Thats hard to notice in their 'maven guide' documentation unless you are looking really carefully. +1 for noticing that and sharing it.Vocational
this answer is pretty much word-for-word copy of my answer from https://mcmap.net/q/247004/-java_home-in-mavenForb
@JunedAhsan So what am I supposed to do here? I am getting the same error. Where do I set the home property?Inseverable
java.home is never set through environment variables. It is set automatically. JAVA_HOME is the thing you can set.Forb
@Forb the op already set JAVA_HOME correctly and yet maven incorrectly pick up the JRE instead of the JDK. Then JunedAhsan replies that java.home is different from JAVA_HOME and when Kraken asks how to set java.home, your answer is to set the JAVA_HOME. Aren't we back to the start? your guys anwsers are not much helping or I am missing somethingTrenatrenail
@Trenatrenail Did you read the answer I linked to? The point of this conversation has been that maven has been correctly pointing to the JDK all the time, it just reports it funnily. There is no error here. OP had completely unrelated issue.Forb
@Trenatrenail the problem Kraken had was solved in this thread - he was missing tools.jar. Again, unrelated issue.Forb
@Juned The link you have given for "Maven Properties Guide" doesn't seem to be working anymore. I'm getting a "We can’t connect to the server at docs.codehaus.org" error. Can you please update it?Unwary
Hi @Unwary Thanks for pointing it out. I have updated with another link.Egoist
O
3

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.

Omora answered 6/3, 2017 at 6:42 Comment(0)
B
3

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
Bankhead answered 7/8, 2018 at 10:11 Comment(0)
T
0

Windows CMD don't refresh environment variables and you need run new instance for applying new environment setting and refresh new variable JAVA_HOME.

Tangle answered 1/9, 2015 at 9:27 Comment(0)
S
0

Once you have the JDK installation path:

  1. Right-click the My Computer icon on your desktop and select Properties.
  2. Click the Advanced tab.
  3. Click the Environment Variables button.
  4. Under System Variables, click New.
  5. Enter the variable name as JAVA_HOME.
  6. Enter the variable value (one of the paths mentioned above) as the installation path for the Java Development Kit.
  7. Click OK.
  8. Click Apply Changes.

You might need to restart windows.

This worked for me.

Storehouse answered 23/10, 2017 at 8:51 Comment(0)
Z
0

You can modify it on this window:

enter image description here

Zeculon answered 8/2, 2019 at 2:8 Comment(0)
T
0

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"

Thievish answered 31/3, 2020 at 20:37 Comment(0)
L
0

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.

Lien answered 4/5, 2022 at 12:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.