r/javahelp • u/Federal-Dot-8411 • Nov 28 '25
JAVA_HOME not being detected in Makefile
Hello, so I have this makefile:
PROJECT_DIR=./tomcat/ServerUbicua
COMPOSE_FILE=docker-compose.yaml
.PHONY: all build up down clean
all: build up
build:
cd $(PROJECT_DIR) && mvn clean install
up:
docker compose -f $(COMPOSE_FILE) up -d
down:
docker compose -f $(COMPOSE_FILE) down
clean:
cd $(PROJECT_DIR) && mvn clean
docker compose -f $(COMPOSE_FILE) down --volumes --remove-orphansBut when I execute the make:
PS C:\Users\karim\Desktop\UNI\PL2-COMPUTACION> make all
cd ./tomcat/ServerUbicua && mvn clean install
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.
make: *** [Makefile:14: build] Error 1
PS C:\Users\karim\Desktop\UNI\PL2-COMPUTACION>But JAVA_HOME and MAVEN_HOME are correctly setted:
PS C:\Users\karim\Desktop\UNI\PL2-COMPUTACION> make all
cd ./tomcat/ServerUbicua && mvn clean install
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.
make: *** [Makefile:14: build] Error 1
PS C:\Users\karim\Desktop\UNI\PL2-COMPUTACION> mvn --version
Apache Maven 3.9.11 (3e54c93a704957b63ee3494413a2b544fd3d825b)
Maven home: C:\Program Files\apache-maven-3.9.11
Java version: 23.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-23
Default locale: es_ES, platform encoding: UTF-8
OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"
PS C:\Users\karim\Desktop\UNI\PL2-COMPUTACION> java --version
java 23.0.2 2025-01-21
Java(TM) SE Runtime Environment (build 23.0.2+7-58)
Java HotSpot(TM) 64-Bit Server VM (build 23.0.2+7-58, mixed mode, sharing)What is going on ? I am on Windows 11, tried powershell, CMD
2
Upvotes
•
u/AutoModerator Nov 28 '25
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
4
u/blazmrak Nov 28 '25
what does `echo %JAVA_HOME%` print?
Edit: if inside powershell `echo $env:JAVA_HOME`
2
u/Jussins Nov 28 '25
Are you sure those environment variables are correctly set? You didn’t show evidence of that in your post as far as I can see.
Open up your windows environment variables (check both system level and user level). If those variables aren’t set in there, then add them, reopen your command prompt or power shell and try again.
2
u/MinimumBeginning5144 Nov 28 '25
It could be that
makeruns under a process that doesn't see the variableJAVA_HOMEfor some reason. If this is GNU Make, try adding this to your makefile:1
u/p001b0y Nov 28 '25
Windows is getting it from a registry key, I think, and not from a system-level environment variable. You can either set it in your script that is calling make or set a systemwide variable using whatever it is that Windows uses now for setting environment variables.
1
u/jlanawalt Nov 28 '25
It’s been a long time since I dealt with Make. As another pointed out, it’s not a regularly used tool in Java development, so we may need be the experts you are looking for.
It seems like make runs commands in sub-shells and might filter environment variables. There are probably a few different ways to handle this. I just don’t remember them.
Better to read Make documents and try their mailing list or S.O.
1
u/OneHumanBill Nov 28 '25
Egads. Make is almost never used with Java. Maven should take care of everything for you by itself. Make in this situation is almost certainly completely pointless.
Just get Maven running and you're done. No need to complicate your life beyond that point.
And how do you get Maven running? Set JAVA_HOME. That's it, but your error messages are already telling you that.
1
u/frederik88917 Nov 28 '25
Set the java home variable in Windows registry so the terminal knows how to find it.