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

When running Maven, I get this output:
[WARNING] Unable to autodetect 'javac' path, using 'javac' from the environment.
How do I fix this?

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.

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

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

sudo yum install java-sdk
Centos finds the correct SDK with the -devel sufix

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

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.

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

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

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.

Related

Intellij - No valid Maven installation found when configured to use Maven Wrapper

I've upgraded my IntelliJ Community from 2021.1 to 2021.2 today and now I'm getting the following error when trying to run maven commands:
No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system.
But it's correctly configured to use Maven Wrapper:
My .mvn/wrapper/maven-wrapper.properties is as follow:
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
What am I supposed to do in order to keep using Maven Wrapper? Or is it a possible bug?
It is a bug: IDEA-258757 Cannot start tasks with maven wrapper
UPD: This is fixed in versions 2021.3+

DeepLearning4j examples maven project unable to be processed by Intellij

As shown in the screenshot there is a dependency of the dl4j-0.4-examples project that is unable to be loaded by intellij.
Unable to get dependency information: Unable to read the metadata file
for artifact 'com.github.jai-imageio-core.jar': Invalid JDK version in
profile "java8-and-higher': Unbounded range [1.8
A similar problem resolved in this question
https://github.com/google/gson/issues/596
as quick fix open the pom file at your local repository and add ')'
and should looks like
91 [1.8,)
save and execute again
But in this case there is no jdk tag: so that approach can not be used.
Has anyone found a workaround to load this project into intellij?
The owners of the project have recognized this as an issue. If you would like to follow along here is the bug tracker:
https://github.com/deeplearning4j/dl4j-0.4-examples/issues/76
Update 2/28/16: The resolution: I needed to do
brew switch maven 3.3.9
There were multiple versions of maven installed on my machine but I did not know about brew switch. So some ways maven was working without doing the switch - but for this project a completely clean maven installation was required.

How do you set up Gradle properly and create a new Gradle project for IntelliJ IDEA?

So, I downloaded Gradle but I don't know how to set it up correctly. After I unzipped the zip file, what do I do next? I want to use Gradle in IntelliJ IDEA. From a livestream I've seen I know that there's a settings.gradle and a build.gradle file in the project folder in IntelliJ.
Also, I've seen that they used the windows console.
First of all, how do I access gradle through the windows console and tell it to generate a new project for IntelliJ?
As you can see, I don't have any experience with Gradle. Unfortunately I can't really find out how to use it.
I want the IntelliJ project then to have LWJGL and Slick.
Additionally, I know what it says in the build.gradle file I've seen on the livestream (I only want to create my project with the same structure like theirs).
Can anybody give a detailed description of what to do to achieve all this?
Lets' say you unpacked gradle to d:\tools\gradle.
To add its bin directory it to the PATH in a console window, execute the following command:
set PATH=d:\tools\gradle\bin;%PATH%
The above prepends the bin path to the current value of the PATH environment variable. This will only change the path for this specific command window.
If you want to add it to the PATH globally, then go to your control panel and choose System, then Advanced parameters (it might be something a little bit different: I'm translating from my French version of Windows). Then in the Advanced system parameters tab, click the button Environment variables.... Find the Path environment variable in the list, and add the directory, separated from the others using a semicolon (;).
Note: you can also define a new environment variable called GRADLE_HOME:
set GRADLE_HOME=d:\tools\gradle
or globally, as explained above, and reference it inside the PATH variable:
set PATH=%GRADLE_HOME%\bin;%PATH%
Just intall homebrew.
Then you can just open the terminal and install easy like:
brew install gradle
Done! It's installed!
For test just type in your terminal:
gradle -v
And you'll have something like this:
------------------------------------------------------------
Gradle 2.7
------------------------------------------------------------
Build time: 2015-09-14 07:26:16 UTC
Build number: none
Revision: xxxxxxxxxxxxxxxxxxxxxxxxxx
Groovy: 2.3.10
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_60 (Oracle Corporation 25.60-b23)
OS: Mac OS X 10.11.1 x86_64
Then, open your IntelliJ and create a new gradle project as normal, just setting the gradle's path when necessary (normally in /usr/local/Cellar when installed with homebrew or /opt when installed other ways).
Good luck!
For linux Users,
User SDK Man to easily manage your gradle installation and path settings for development as well as gradle update
GET SDK MAN HERE
(for mac os users) Let's assume, you unpacked zip file into /Users/onuryilmaz/gradle-3.3 folder. Then open terminal and define a new environment variable called GRADLE_HOME:
export GRADLE_HOME=/Users/onuryilmaz/gradle-3.3
After that reference it inside the PATH variable:
export PATH=$PATH:$GRADLE_HOME/bin
just update the brew and install and set path that's all
brew update && brew install gradle
export PATH=$PATH:/opt/gradle/gradle-5.1.1/bin
https://gradle.org/install/

Unable to download the artifact maven-compiler-plugin from repository

I've created a maven project and wanted to change the java compiler version to 1.6 so I added the ff:
<build>
<plugins>
<plugin>
<artifactId>org.apache.maven.plugins</artifactId>
<groupId>maven-compiler-plugin</groupId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
When I run any maven goal in eclipse, it works. But when I run in terminal I got the ff errors:
Project ID: maven-compiler-plugin:org.apache.maven.plugins
Reason: POM 'maven-compiler-plugin:org.apache.maven.plugins' not found in repository: Unable to download the artifact from any repository
maven-compiler-plugin:org.apache.maven.plugins:pom:2.3.2
from the specified remote repositories:
central (http://repo1.maven.org/maven2),
apache.repo (https://repository.apache.org/content/repositories/releases),
jboss.repo.deprecated (https://repository.jboss.org/nexus/content/repositories/deprecated),
Any idea what's causing this issue?
I was able to solved this issue by updating to maven3. But my problem right now is although I specified maven-compiler-plugin version to be 2.4, I'm still seeing 2.3.2 in the log.
Your groupId and artifactId are reversed.
If Eclipse and the command line create different results, then they use different local Maven repositories. The default is in $HOME/.m2/repository/. So the first step is to find out which one (command line or Eclipse) uses a different local cache and why.
The next question is why the download failed. The usual reason is that Maven tried the download and got an error. Maven will remember the error and not try again. To force it to try again, you have to delete the folder $M2_REPO/repository/org/apache/maven/plugins/maven-compiler-plugin/2.3.2/.
Lastly, when you configure 2.4 but see 2.3.2 in the log, then you're either building the wrong project of one of the POMs of your build overwrites the version for the compiler plugin.
To avoid issues like this, use a parent POM where you keep all the versions in dependencyManagement (for dependencies) and pluginManagement (for plugins) elements. That way, you will never have to define a version in a module POM or in other projects which inherit from this one.
After installing maven 3 from a repository and added maven3 home in /etc/environment what I forgot to do is to reboot my machine, after that it worked.
My /etc/environment now looks like:
M3_HOME="/home/edward/java/apache/maven-3.0.4"
MAVEN_HOME="/home/edward/java/apache/maven-3.0.4"
M3="home/edward/java/apache/maven-3.0.4"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/edward/java/apache/maven-3.0.4"
Here's how I uninstalled and install maven 3:
http://czetsuya-tech.blogspot.com/2012/05/how-to-install-maven-3-in-ubuntu-1110.html

Java 7 && IntelliJ

I installed openjdk 1.7.0 and set it up in IntelliJ 10.5
When I compile (anything) I get the error "Fatal Error: Unable to find package java.lang in classpath or bootclasspath".
I looked at this question:
IntelliJ gives Fatal Error: Unable to find package java.lang in classpath or bootclasspath but all jar files inside the lib directory are already added.
Ok. I was wrong there weren't all jars added. I found some more in (sub)directories other than 'lib'. After adding all those manually everything is fine. Seems like even IDEA 10.5.2 does not like the structure in openJDK yet.
Try IDEA 10.5.2. Make sure that JDK path is not a symlink. If the issue remains, specify your OS and attach a screenshot of JDK classpath configured in IDEA.
I had the same problem. I added all jar files in the following directories manually:
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/1.7.0.jre/Contents/Home/lib
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/1.7.0.jre/Contents/Home/lib/ext