When building Java projects with Maven, encountering the error “fatal error compiling: invalid target release: 11” indicates a mismatch between the Java version specified in your project and the Java Development Kit (JDK) installed on your system. This error is significant because it can halt the build process, preventing successful compilation and deployment of your application. Ensuring compatibility between Maven and the JDK is crucial for smooth and efficient Java development workflows.
The error “Maven is not using Java 11: Fatal error compiling: invalid target release 11″ indicates that Maven is configured to compile your project with Java 11, but it can’t find the Java 11 Development Kit (JDK) on your system. Here are the common causes:
Incorrect Java Version Settings:
pom.xml
file specifies the correct Java version:<properties>
<maven.compiler.source>11</maven.compiler.target>11</properties>
JAVA_HOME
points to the JDK 11 installation directory.Missing JDK 11:
java -version
in your terminal. If not installed, download and install it from the official Oracle website or other distributions like AdoptOpenJDK.JAVA_HOME
environment variable to the JDK 11 path and update your system’s PATH variable to include JAVA_HOME/bin
.IDE Configuration:
By addressing these common causes, you should be able to resolve the error and successfully compile your project with Maven using Java 11.
To check if Java 11 is installed and resolve the Maven error, follow these steps:
Open Terminal:
Check Java Version:
java -version
and press Enter.Set JAVA_HOME Environment Variable:
JAVA_HOME
with the path to your JDK 11 installation (e.g., C:\Program Files\Java\jdk-11
).Path
variable and add %JAVA_HOME%\bin
..bash_profile
, .zshrc
).export JAVA_HOME=$(/usr/libexec/java_home -v11)
export PATH=$JAVA_HOME/bin:$PATH
source ~/.bash_profile
or source ~/.zshrc
.Verify Maven Configuration:
mvn -version
to ensure Maven is using Java 11.These steps should help you resolve the Maven error related to Java 11.
Here are the steps to set the JAVA_HOME
environment variable to point to JDK 11 for different operating systems:
This PC
> Properties
> Advanced system settings
.Environment Variables
.System variables
, click New
.Variable name
to JAVA_HOME
.Variable value
to the JDK installation path (e.g., C:\Program Files\Java\jdk-11
).OK
.System variables
section, find and select the Path
variable, then click Edit
.New
and add %JAVA_HOME%\bin
.OK
to save.~/.bash_profile
or ~/.zshrc
):nano ~/.bash_profile
export JAVA_HOME=$(/usr/libexec/java_home -v 11)
export PATH=$JAVA_HOME/bin:$PATH
source ~/.bash_profile
sudo apt install openjdk-11-jdk
for Debian-based systems).~/.bashrc
or ~/.profile
):nano ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
source ~/.bashrc
Verify Java Installation:
java -version
Ensure it shows JDK 11.
Configure Maven to Use JDK 11:
pom.xml
file to specify the Java version:<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
Verify Maven Configuration:
mvn -version
Ensure it shows JDK 11.
These steps should help you resolve the “Maven is not using Java 11” error.
Open your pom.xml
file.
Add the following properties to specify the Java version:
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
Configure the Maven Compiler Plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
These steps should resolve the “maven is not using java 11 fatal error compiling invalid target release 11” issue.
Verify JDK 11 Installation:
java -version
Set JAVA_HOME Environment Variable:
setx JAVA_HOME "C:\Program Files\Java\jdk-11"
setx PATH "%JAVA_HOME%\bin;%PATH%"
export JAVA_HOME=$(/usr/libexec/java_home -v 11)
export PATH=$JAVA_HOME/bin:$PATH
Configure Maven to Use JDK 11:
Add to pom.xml
:
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
Verify Maven Configuration:
mvn -version
These steps should resolve the “maven is not using java 11 fatal error compiling invalid target release 11” issue.
Follow these steps:
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>