Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Sample Java (Maven) - JDK 21 Setup on Windows

This project targets Java 21 and enforces it using the Maven Toolchains plugin.

Prerequisites

  • JDK 21 installed (Microsoft, Adoptium, Oracle, etc.)
  • Maven 3.9+ recommended

Configure Maven Toolchains

  1. Locate your JDK 21 installation path. Common examples:
    • C:\Program Files\Microsoft\jdk-21 (Microsoft Build of OpenJDK)
    • C:\Program Files\Eclipse Adoptium\jdk-21.* (Adoptium Temurin)
    • C:\Program Files\Java\jdk-21 (Oracle/OpenJDK)
  2. Copy the provided toolchains.xml into your Maven user home:
    • Windows: %USERPROFILE%\.m2\toolchains.xml
  3. Edit the <jdkHome> in toolchains.xml to match your actual JDK 21 path.

Note: The project includes maven-toolchains-plugin requiring JDK [21,). Maven will resolve the matching toolchain and use it for compilation.

Build & Test

# From repository root or project folder
mvn -f "c:\Users\sures\OneDrive\My Research\Jafima 2.0\.github\sample-java\pom.xml" clean package
mvn -f "c:\Users\sures\OneDrive\My Research\Jafima 2.0\.github\sample-java\pom.xml" test

Enforce toolchains during build (optional)

Enable the profile to require Maven to use JDK 21 via toolchains:

mvn -f "c:\Users\sures\OneDrive\My Research\Jafima 2.0\.github\sample-java\pom.xml" -DenforceToolchain=true clean package

If your Maven version supports it, you can point to the project toolchains.xml without copying:

mvn -f "c:\Users\sures\OneDrive\My Research\Jafima 2.0\.github\sample-java\pom.xml" -DenforceToolchain=true -Dmaven.toolchains.location="c:\Users\sures\OneDrive\My Research\Jafima 2.0\.github\sample-java\toolchains.xml" clean package

Troubleshooting

  • "No toolchain found for type jdk" → Ensure %USERPROFILE%\.m2\toolchains.xml exists and <version> is 21.
  • "Invalid JDK path" → Verify <jdkHome> points to a valid bin\java.exe.
  • Build still using another JDK → Confirm you don’t have a conflicting JAVA_HOME or PATH; Maven Toolchains should override for compilation, but global tools may still reference JAVA_HOME.