Maven: WARNING Unable to autodetect 'javac' path, using 'javac' from the environment

You will see this error message when Maven is being run using a JRE (Java Runtime Environment) which is a stripped down version of Java that can only execute Java code but can't compile sources.

To fix the warning, install the SDK (Source Development Kit) and set the environment variable JAVA_HOME to the newly installed version of Java.

You can put this into the file .mavenrc if you want; then only Maven will use this version of Java.


If you're running Maven from Eclipse (e.g. Run As : Maven Install), make sure your environment is configured with correct JRE (you'll need JDK, not JRE). Go to Window -> Preferences -> Java -> Installed JRE. Select JDK if it's there or add JDK if it's not.


A friend of mine experienced this issue when working on building a Java project in Ubuntu 18.04.

When he runs the command:

maven clean build

He gets the warning:

[WARNING] Unable to autodetect 'javac' path, using 'javac' from the environment

And then gets this error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project geostore-model: Compilation failure -> [Help 1]

Here's how it was solved:

The issue was that he did not have javac (Java programming language compiler) installed on his machine. To confirm, we ran the command:

javac --version

And we got no version output

So we installed the Java development kit that contains javac and all of its dependencies using the command:

sudo apt install default-jdk

Afterwhich we ran the command javac --version and got the output:

javac 11.0.9.1

That's all.

I hope this helps