JAVA_HOME should point to a JDK not a JRE
Control Panel -> System and Security -> System -> Advanced system settings -> Advanced -> Environment Variables -> New System Variable
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.
Maven installation issues: JAVA_HOME should point to a JDK not JRE?
OK, take a deep breath, and we'll walk through this. Each of these environment variables has a purpose, and once you understand what those purposes are, this makes a lot more sense. Mixing tutorials is not necessarily a problem, but you'll want to understand what you're doing, rather than just blindly copy values from the internet.
JAVA_HOME
is intended to identify to the system environment where to find a java runtime environment. It needs to be set to the full path of where your JDK has been installed. On windows, this might beC:\Program Files\Java\jdk-13.0.1
. On a Linux system, you have a bit more flexibility. Common locations might be/opt/java/jdk-13.0.1
or/usr/local/java/jdk-13.0.1
. If you installed your JDK somewhere else, then you need to use that path instead. The messageNB: JAVA_HOME should point to a JDK not a JRE
refers to a common mistake when installing maven -- maven requires a JDK, not a plain JRE. This error is so common that any timeJAVA_HOME
points to a folder that isn't a JDK, it prints this warning (even if the folder in question isn't actually a JRE).M2_HOME
is supposed to be set to the full path where maven is installed (i.e. the place where you unzipped it). This more or less helps maven "find itself" if it should need to for whatever reason. Strictly speaking, this one isn't necessary. (It's not set on my system, and maven works fine for me). It's mostly a convenience for setting the next environment variable.M2
is the full path to the folder where the maven executable is. This will almost always be$M2_HOME/bin
, but it's certainly possible to do weird things, and this will let you work around those situations. Obviously, this won't work if you didn't specify$M2_HOME
. This one isn't strictly necessary, either, and is mostly a convenient way of setting up the next one.PATH
is where your Linux system looks to find programs to run when you type their name on the command line. For ease of use, you'll want to make sure that the maven and java executables are included somewhere in the:
delimited list. Most Linux distributions already have a defaultPATH
set up for you in a shell resource file of some kind. You'll want to refer to their documentation for how to add another entry to the path, but a common idiom would bePATH=$PATH:$M2
(which would append the value of$M2
to the value of$PATH
and then store the result back intoPATH
. If you didn't set up$M2
or$M2_HOME
, you'll need to do something else.
So, TL;DR, if you installed your JDK in /opt/java/jdk-13.0.1
and unzipped maven into /opt/maven/apache-maven-3.6.3
, your bear minimum working values are:
export JAVA_HOME=/opt/java/jdk-13.0.1
export PATH=$PATH:$JAVA_HOME/bin:/opt/maven/apache-maven-3.6.3/bin
And if you wanted a complete set
export JAVA_HOME=/opt/java/jdk-13.0.1
export M2_HOME=/opt/maven/apache-maven-3.6.3
export M2=$M2_HOME/bin
export PATH=$PATH:$JAVA_HOME/bin:$M2
It's worth noting that most Java IDEs will include a GUI for setting up maven and Java within the IDE (the settings will typically only work within that IDE). It's often much easier for beginners to get up and running that way.
Should JAVA_HOME point to JDK or JRE?
If you're doing any sort of development, or building with Maven or Ant, you need to point to the JDK (Java Development Kit) where utilities such as javac
(the Java Compiler) reside. Otherwise, you can point to the JRE (Java Runtime Environment).
The JDK contains everything the JRE has and more. If you're just executing Java programs, you can point to either the JRE or the JDK.
JAVA_HOME should point to a JDK not a JRE + JAVA_HOME is not defined correctly
JAVA_HOME
sould point to the base installation dir of java:/usr/lib/jvm/java-11-openjdk-amd64/
not /usr/bin/java
which probably is a symbolic link to /usr/lib/jvm/java-11-openjdk-amd64/bin/java
then in PATH
variable you append $JAVA_HOME/bin
So it should look something like this:
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
PATH=$JAVA_HOME/bin:$PATH
FYI update-alternatives is only responsible for changing the symlink of java to point it to different versions of the executable,
think of it as a simple ln -s /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/bin/java
Bamboo fails with JAVA_HOME should point to a JDK not a JRE in Maven task on CentOS 7
So, it is not about how you set the JAVA_HOME
variable for Bamboo, but it's about how Bamboo sets its JAVA_HOME
variable for it's java executable. It is in the database. It was the value before I made an update to java and deleted the old version and I have changed it from Bamboo administration > JDKs
to /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre
and done, the issue is resolved.
Setting up Tomcat 7 on server: NB: JAVA_HOME should point to a JDK not JRE... Why?
Tomcat does not require a JDK. Tomcat ships with the Eclipse JDT compiler which Tomcat uses as part of the *.jsp -> *.java -> *.class process to convert JSPs to compiled Servlets.
However, if you specify JAVA_HOME, Tomcat expects that to point to a full JDK installation. If you want to use a JRE then you need to set JRE_HOME rather than JAVA_HOME.
Related Topics
How to Unzip Files Recursively in Java
Why Are Variables Declared with Their Interface Name in Java
Override "Private" Method in Java
Remove Duplicates from Arraylists
Java.Sql.Sqlexception: No Suitable Driver Found for Jdbc:Mysql://Localhost:3306/Dbname
Java: Global Exception Handler
Creating Runnable Jar with External Files Included
Jaxb :Need Namespace Prefix to All the Elements
Why Can't I Use \U000D and \U000A as Cr and Lf in Java
Are Thread.Sleep(0) and Thread.Yield() Statements Equivalent
How to Programmatically Inject a Java Cdi Managed Bean into a Local Variable in a (Static) Method
404 Error Redirect in Spring with Java Config
How to Concatenate Characters in Java