Apache Maven is an popular build automation tool used for the Java based applications. A more common issue that developers encounter is the error message “Invalid Target Release: 11”. Generally this error occurs when Maven is trying to compile code with specific Java version that may not be installed on your machine (in this case, Java 11).

Advertisement

You should not worry more about it. It is a common issue practices by many users. This tutorial will help you to understand more about this issue and help you to resolve it easily.

Understanding the Error

The “Invalid Target Release: 11” error means that Maven is configured to compile the code with Java 11, but it cannot find Java 11 Development Kit (JDK) on your system. This discrepancy can arise due to several reasons:

  • The JDK 11 is not installed on your machine.
  • Maven is not configured to use JDK 11.
  • Environmental variables are not set correctly to point to JDK 11.

Step-by-Step Solution

Have a sip of coffee and be ready to resolve this issue using following steps:

Step 1: Verify Java Installation

First, make sure JDK 11 is installed on your system. You can check this by opening a terminal or command prompt and typing:

java -version

If JDK 11 is not installed, download and install it from the official Oracle website or adopt a version from distributions like AdoptOpenJDK.

Step 2: Set JAVA_HOME Environment Variable

After installing JDK 11, you need to set the JAVA_HOME environment variable to point to your JDK installation directory.

On Windows:

  1. Search for “Environment Variables” in the Start menu and open the dialog.
  2. Under “System Variables”, click “New” and add a variable named JAVA_HOME with the path to your JDK 11 installation (e.g., C:\Program Files\Java\jdk-11).
  3. Find the Path variable, select it, click “Edit”, and add “%JAVA_HOME%\bin” to the list.

On macOS/Linux:

  1. Open your shell profile file (e.g., .bash_profile, .zshrc) and add:
    
    export JAVA_HOME=$(/usr/libexec/java_home -v11)
    export PATH=$JAVA_HOME/bin:$PATH
    
    
  2. Save the file
  3. Apply the changes by running source ~/.bash_profile or source ~/.zshrc.

Step 3: Configure Maven to Use JDK 11

Ensure that Maven is configured to use JDK 11 by specifying the source and target release in your project’s pom.xml file:


<properties>
  <maven.compiler.source>11</maven.compiler.target>11
</properties>

Step 4: Verify Maven Configuration

Finally, verify that Maven is using the correct JDK version by running:

mvn -version

This command will display the Maven version, along with the Java version it’s using. Ensure it matches JDK 11.

Conclusion

Hope this tutorial resolves “Invalid Target Release: 11” error on your system. By following these steps, you should be able to compile your project without encountering this error. If you continue to face issues, consider consulting the documentation for your IDE or build system, as there may be additional configuration steps required.

Share.
Leave A Reply


Exit mobile version