How to Fix Maven Error: “Invalid target release: 11”

19 feb 2024 2 min di lettura
How to Fix Maven Error: “Invalid target release: 11”
Indice dei contenuti

Introduction

When working with Maven, a common problem encountered by developers is the "Invalid target drop: 11" error message. This error typically occurs when Maven tries to compile Java code targeting a Java version (in this case Java 11) that is not available or configured correctly in the environment. This article will guide you through the steps to resolve this issue effectively.

Understand the mistake

The "Invalid Target Release: 11" error means that Maven is prompted to compile code with Java 11, but cannot find the appropriate Java Development Kit (JDK) version. This discrepancy can occur for several reasons:

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

Step by step solution

Step 1: Verify your 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 Oracle's official website or adopt a version from distributions such as AdoptOpenJDK.

Step 2: Set the JAVA_HOME environment variable

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

On Windows:

  1. Search for "Environment Variables" in the Start menu and open the dialog box.
  2. Under "System Variables", click "New" and add a variable called JAVA_HOME with the path to your JDK 11 installation (for example, 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:

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

Save the file

Apply the changes by running source ~/.bash_profile or source ~/.zshrc.

Step 3: Configure Maven to use JDK 11

Make sure Maven is configured to use JDK 11 by specifying the source and target version in your project's pom.xml file:

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

Step 4: Check your Maven configuration

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

mvn -version

This command will display the version of Maven, along with the version of Java it is using. Make sure it matches JDK 11.

Conclusion

Resolving the "Invalid target release: 11" error in Maven involves ensuring that JDK 11 is installed, setting environment variables correctly, and configuring Maven to use the correct JDK version. By following these steps, you should be able to compile your project without encountering this error. If you continue to experience problems, consider checking the documentation for your IDE or build system, as additional configuration steps may be required.

Support us with a

Successivamente, completa il checkout per l'accesso completo a Noviello.it.
Bentornato! Accesso eseguito correttamente.
Ti sei abbonato con successo a Noviello.it.
Successo! Il tuo account è completamente attivato, ora hai accesso a tutti i contenuti.
Operazione riuscita. Le tue informazioni di fatturazione sono state aggiornate.
La tua fatturazione non è stata aggiornata.