Error: JAVA_HOME is not defined correctly executing maven
Assuming you use bash shell and installed Java with the Oracle installer, you could add the following to your .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/jre/bin:$PATH
This would pick the correct JAVA_HOME
as defined by the Oracle installer and will set it first in your $PATH
making sure it is found.
Also, you don't need to change it later when updating Java.
EDIT
As per the comments:
Making it persistent after a reboot
Just add those lines in the shell configuration file. (Assuming it's bash
)
Ex: .bashrc
, .bash_profile
or .profile
(for ubuntu)
Using a custom Java installation
Set JAVA_HOME
to the root folder of the custom Java installation path without the $()
.
Ex: JAVA_HOME=/opt/java/openjdk
How do I fix maven error The JAVA_HOME environment variable is not defined correctly?
The SETX
command does not modify the current environment.
If you run the following batch file:
setx AAA aaa
echo AAA=%AAA%
It will print
AAA=
So your batch file is wrong. You have to use set
:
set AAA=aaa
See What is the difference between SETX and SET in environment variables in Windows.
Error the JAVA_HOME environment variable is not defined correctly on running mvn clean javadoc:jar package
I would remove the above listed packages with pattern openjdk-11-.*
(see this question) and install Java like this.
Showing JAVA_HOME is not defined correctly when I check Maven version in windows 10
Take the \bin off your JAVA_HOME variable.
Maven JAVA_HOME environment variable is not defined correctly, but it is
Your JAVA_HOME is incorrect.
JAVA_HOME should be "C:\Program Files\Java\jdk-11.0.2"
Remember to reopen new console after reset JAVA_HOME environment to apply new value.
Related Topics
How to Reference a Method in Javadoc
Java Conditional Operator : Result Type
How to Get the Http Status Code Out of a Servletresponse in a Servletfilter
Java File - Open a File and Write to It
Integer VS Int: with Regard to Memory
Can a Class Have No Constructor
Eclipse Error: Could Not Find or Load Main Class
Sslhandshakeexception: No Subject Alternative Names Present
What Is the Largest Possible Heap Size with a 64-Bit Jvm
How to Simulate a Real Mouse Click Using Java
Print All the Spring Beans That Are Loaded
Making a Log4J Console Appender Use Different Colors for Different Threads
How to Configure Log4J to Log Different Log Levels to Different Files for the Same Logger
Can Add Extra Field(S) to @Manytomany Hibernate Extra Table
Why Is My Jlabel Not Showing Up
How to Determine If a Point Is Inside a 2D Convex Polygon