Home > Java > Trying to build the program using a JDK version that is not installed

Trying to build the program using a JDK version that is not installed

PHPz
Release: 2024-02-09 17:06:10
forward
952 people have browsed it

php editor Xinyi introduces you how to try to build a program using an uninstalled JDK version. During development, it is crucial to use the correct JDK version, but sometimes we may need to try using other versions to solve some problems. At this time, we can specify the JDK version to be used by setting environment variables and use command line tools to build our program. In this article, we will explain in detail how to do these operations to help you successfully complete your development tasks. let's start!

Question content

I installed jdk-21 on a windows computer using the oracle installer. But when I tried to build the project I got an error saying gradlew is incompatible so I uninstalled oracle jdk-21 and now I have installed adoptium build and set java_home

using this command

setx java_home "c:\program files\eclipse adoptium\jdk-21.0.1.12-hotspot"

When I run where java in command prompt, I get:

c:\program files\eclipse adoptium\jdk.21.0.1.12-hotspot\bin\java.exe
Copy after login

However, when I try to build the project, I get an error message stating that the java executable "c:\program files\java\jdk-21\bin\java.exe" cannot be found. My computer seems to be trying to find the version of oracle I uninstalled.

I followed the instructions in this article and set %java_home%\bin in the system path, but it says the executable cannot be found.

This is the first entry in my environment variable path

c:\program files\eclipse adoptium\jdk-21.0.1.12-hotspot\bin
Copy after login

This is my last article

%JAVA_HOME%\bin
Copy after login

Why does the program want to build with the uninstalled java version (i.e. the oracle version I removed)?

This link shows a screenshot of the java path on my windows machine.

This java spring project is what I'm trying to build.

Solution

Maybe this is related to the gradle caching mechanism. Delete the .gradle/daemon/<version>/registry.bin file, it should use your JAVA_HOME environment variable.

Here is the gradle daemon documentation. Maybe this part causes the subsequent error you describe in your comment. You can use gradle <task> --no-daemon to disable the current build daemon and check if your project will build.

The project you linked to is using Gradle 8.0.1. Running it with Java 21 is not supported, you can see that in https://docs.gradle.org/current/userguide/compatibility.html. Therefore, to build this project unchanged, you must run Gradle with up to Java 19.

Still using the old Java installation even if JAVA_HOME is set to the new location sounds strange if you actually run Gradle from the command line. If you run it from an IDE, you must check the IDE settings.

Now I can only imagine that in your GRADLE_USER_HOME (usually .gradle/ in your user home directory) you have a gradle.properties where you can set the path to your old Java installation.

If this is not the case, the question is, what is the exact output of you trying to run the build, and where exactly is the error coming from. If it's coming from a Gradle wrapper script, you can turn off echo suppression to see what actually happens.

The above is the detailed content of Trying to build the program using a JDK version that is not installed. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template