Aaron Digulla
Aaron Digulla

Reputation: 328760

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

When running Maven, I get this output:

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

How do I fix this?

Upvotes: 24

Views: 63770

Answers (14)

Kiruthika kanagarajan
Kiruthika kanagarajan

Reputation: 954

sudo yum install java-sdk

Centos finds the correct SDK with the -devel suffix

Upvotes: 1

eprimmer
eprimmer

Reputation: 1

I was still getting this error, even though I had updated my path etc. and javac -version was giving the right version of Java.

I fixed it by just restarting my computer :), so that is worth trying as well if the problem persists.

Upvotes: 0

Heverton Silva Cruz
Heverton Silva Cruz

Reputation: 47

analised:

<plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <executable>/usr/local/pje/jdk-11.0.10+9/bin/javac</executable>
            </configuration>
        </plugin>

Upvotes: 0

romeucr
romeucr

Reputation: 229

I am using IntelliJ 2022.3.2 and had to remove the "\bin" part from my JAVA_HOME path to fix the "problem".

Upvotes: 0

randomperson
randomperson

Reputation: 1

On Mac deleting the .idea folder in intelliJ worked for me

Upvotes: 0

Dzeri96
Dzeri96

Reputation: 432

For people who don't find that the accepted answer applies: check if your maven-compiler-plugin has the fork option set to true in pom.xml, like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <fork>true</fork>
    </configuration>
</plugin>

This seems to be a bug in IntelliJ that hasn't been fixed as of 21.10.2022.

Upvotes: 1

Chris Wu
Chris Wu

Reputation: 327

If you are using IntelliJ:
Check Preferences | Build, Execution, Deployment | Build Tools | Maven | Runner -> JRE.
Also check File | Project Structure.
Most of the time you will find a wrong java version.

Upvotes: 1

Aaron Digulla
Aaron Digulla

Reputation: 328760

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 JDK (Java 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.

Upvotes: 26

Wolfgang Fahl
Wolfgang Fahl

Reputation: 15594

On a Mac:

java_version=1.8
#version=1.8.0_91
export JAVA_HOME=$(/usr/libexec/java_home -v $java_version) 

Upvotes: 0

Kiruthika kanagarajan
Kiruthika kanagarajan

Reputation: 954

sudo yum install java-1.8.0-openjdk-devel for java version 8 sudo yum install java-11-openjdk-devel for java version 11

Upvotes: 1

Promise Preston
Promise Preston

Reputation: 29068

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

Upvotes: 7

Mehraj Malik
Mehraj Malik

Reputation: 15874

Right click on project -> Properties -> Java Compiler then uncheck Use compliance from execution environment... and then select a compiler in Compiler Compliance level

Upvotes: 0

user3458
user3458

Reputation:

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.

Upvotes: 8

vinay Maneti
vinay Maneti

Reputation: 1451

try to set JAVA_HOME in the MyComputer-->Environment Variable

Upvotes: 1

Related Questions