Maven Java Home Path: \bin, or not to \bin - java

So I find myself kind of stuck in between.
I set JAVA_HOME to C:\Program Files\Java\jdk1.8.0_121 then Maven works but
java -version
shows 'java' is not recognized as an internal or external command,
operable program or batch file.
If I set JAVA_HOME to C:\Program Files\Java\jdk1.8.0_121\bin, Maven doesn't work but at least I get java -version right.
I'm pretty sure I'm doing something fundamentally wrong but I can't put my finger on it, obviously :(

java -version will look at your $PATH, so normally we need to add %JAVA_HOME%/bin to $PATH for any ad-hoc command. For maven, internally it checks $JAVA_HOME/bin. Hope it helps.

Related

Maven installation issues: JAVA_HOME should point to a JDK not JRE?

I'm super new to CS and very unfamiliar with UNIX/Bash vocab.
I'm currently trying to install Maven, and I made a few mistakes by copy pasting old installation instructions (with incorrect version numbers) and now the whole process is so messed up. I first tried to follow the given instructions on the website, that didn't work, then I tried a few other ones, and now I'm worried that I'm left with a mess by following different sets of instructions.
I've reached a point now where if I type in mvn -version I get the following:
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
Originally, my JAVA_HOME was set to jdk-install-dir, which still gave me the above error message. I tried redownloading the jdk (version 13.0.1) from Oracle, dragged that file to my home directory, and unzipped it. Then I set my JAVA_HOME to that unzipped file, jdk-13.0.1.jdk, and updated my PATH variable. After all this, I'm still getting this same error message, and I'm not sure what to do.
For the reference, here are what some relevant environment variables are set to (I didn't include irrelevant info from PATH):
~ echo $JAVA_HOME
jdk-13.0.1.jdk
~ echo $PATH
/usr/local/apache-maven/apache-maven-3.6.3/bin:/opt/apache-maven-3.6.3/bin:jdk-install-dir/bin:/usr/local/apache-maven/apache-maven-3.3.9/bin:/opt/apache-maven-3.6.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/allyson/apache-maven-3.6.3/bin:/Users/allyson/apache-maven-3.6.3/bin:jdk-12.0.1.jdk/bin:/Users/allyson/apache-maven-3.6.3/bin:JDK-13.0.1.jdk/bin
~ echo $M2
/usr/local/apache-maven/apache-maven-3.6.3/bin
~ echo $M2_HOME
/Users/allyson/apache-maven-3.6.3
One thing I'm curious about: for the M2 and M2_HOME variables, is it supposed to be that one is in my home directory (/Users/allyson) and one is for /usr/local?
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 be C:\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 message NB: 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 time JAVA_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 default PATH 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 be PATH=$PATH:$M2 (which would append the value of $M2 to the value of $PATH and then store the result back into PATH. 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.
$JAVA_HOME should be a full path, not the dir name.
scream#kafka1:~$ echo $JAVA_HOME
/opt/java/jdk-11.0.5/
scream#kafka1:~$
I'm working on Ubuntu 20, and my own issue was about the jdk version located in the JAVA_HOME variable, which wasn't the right version. This was my trip around that issue:
First, What is the JAVA_HOME value?
$ echo $JAVA_HOME
$ /usr/lib/jvm/jdk-11.0.10
Next question/step, where is the Java app pointing to?
(Source: https://stackoverflow.com/a/42706056/2373421)
$ java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home'
java.home = /usr/lib/jvm/jdk-11.0.12
So, the JAVA_HOME variable wasn't keeping the right value. Let's change that:
$ export JAVA_HOME=/usr/lib/jvm/jdk-11.0.12
The test outcome is right now:
$ mvn -v
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /opt/apache-maven-3.8.1
Java version: 11.0.12, vendor: Oracle Corporation, runtime: /usr/lib/jvm/jdk-11.0.12
I'm doing this for future me's bc after all the links in StackOverflow, the solution was to check mvn.cmd file on C:\Program Files\Maven\apache-maven-3.6.3\bin...
On line 52 it sets the JDK, but it didn't had the "/bin" where my OpenJDK 15 stored the java.exe
This fixed the issue on Windows 11 but it could serve as an idea for other OS. Hope that it helps!

Ant not using my JAVA_HOME to find tools.jar

I realize that this question is going to initially sound like a duplicate of some other questions, but none of the other questions I've looked at fixed my issue.
The short story is that I have a JRE and a JDK installed at different locations. I set JAVA_HOME to point to the JDK, yet ant seems to still search for tools.jar in the JRE location. I'm not sure if this has more to do with my ant installation/configuration, or my JDK installation/configuration.
Here's the long story:
Environment
I am running on Red Hat Enterprise Linux Server release 7.5 (Maipo) on an account that does not have sudo privileges to anything.
My JDK install
The machine already has the JRE installed at /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/jre/bin/java. I am not allowed to modify that install, but I can create my own java installation in a separate location.
The security requirements on my network are very stringent and I am only allowed to put specific pieces of software on the machine. It is possible to ask permission for other pieces of software, but I have to go through an approval process that is a huge pain. I have obtained permission to put JDK 1.8 from openJDK on the machine.
Since openJDK does not release tar balls of the whole installation and since I don't have sudo permissions I attempted to install the JDK by downloading java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64.rpm and java-1.8.0-openjdk-devel-1.8.0.172-13.b11.fc29.x86_64.rpm to /local/apps/openJDK8 and running (from /local/apps/openJDK8)
rpm2cpio < java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64.rpm | cpio -i --make-directories
rpm2cpio < java-1.8.0-openjdk-devel-1.8.0.172-13.b11.fc29.x86_64.rpm | cpio -i --make-directories
For some reason this doesn't seem to do a complete JDK install (I think I must be missing some dependencies). I discovered that libjava.so, libjvm.so, jvm.cfg, and the server folder were missing, so I just created some links to the JRE install that had them (run from local/apps/openJDK8):
ln -s /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/amd64/jvm.cfg usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64/lib/amd64/jvm.cfg
ln -s /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/amd64/libjava.so usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64/lib/amd64/libjava.so
ln -s /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/amd64/libjvm.so usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64/lib/amd64/libjvm.so
ln -s /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/amd64/server usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64/lib/amd64/server
That step makes me a little nervous, so it could be part of my problem. At any rate, javac and java seem to work fine.
ANT INSTALL
For my ant installation, I just downloaded a tar ball and extracted it to /local/apps/ant and then did:
export JAVA_HOME=/local/apps/openJDK8/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64
export ANT_HOME=/local/apps/ant/apache-ant-1.10.4
I didn't bother updating the path because for now I'm just using fully qualified paths for everything. My ultimate goal is to have Jenkins running all of this anyway and it just uses fully qualified paths.
Results
Now if I try to run ant, I get:
> /local/apps/ant/apache-ant-1.10.4/bin/ant
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/tools.jar
Buildfile: build.xml does not exist!
Build failed
The build.xml does not exist part is of course expected, but the inability to locate tools.jar needs to be resolved. The strangest part for me is that according to the error message, it is actually looking for it in the JRE installation location.
Since ant itself is just a shell script, I modified it to print out a little more information by adding the following lines to the end of the file so that it looks like:
echo Running $ant_exec_command $ant_exec_args
echo JAVA_HOME = $JAVA_HOME
echo JAVACMD = $JAVACMD
echo CLASSPATH = $CLASSPATH
echo LOCALCLASSPATH = $LOCALCLASSPATH
echo ANT_HOME = $ANT_HOME
echo ANT_LIB = $ANT_LIB
eval "$ant_exec_command $ant_exec_args"
Now the output is:
$ /local/apps/ant/apache-ant-1.10.4/bin/ant
JAVA_HOME is /local/apps/openJDK8/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64
Running exec "$JAVACMD" -classpath "$LOCALCLASSPATH" -Dant.home="$ANT_HOME" -Dant.library.dir="$ANT_LIB" org.apache.tools.ant.launch.Launcher -cp "$CLASSPATH"
JAVA_HOME = /local/apps/openJDK8/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64
JAVACMD = /local/apps/openJDK8/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64/bin/java
CLASSPATH =
LOCALCLASSPATH = /local/apps/ant/apache-ant-1.10.4/lib/ant-launcher.jar
ANT_HOME = /local/apps/ant/apache-ant-1.10.4
ANT_LIB = /local/apps/ant/apache-ant-1.10.4/lib
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/tools.jar
Buildfile: build.xml does not exist!
Build failed
So JAVA_HOME is clearly set. I can even verify further that ant is actually using the JAVA_HOME value that I set for at least some things because if I remove all of those links I created in my JDK install, it will complain that it can't find libjava.so.
So ant is clearly using my JDK install for at least a little bit, but still looking in the old JRE install for tools.jar.
Any ideas on what is going on?
Figured it out :)
This fix still feels a little more like a workaround than an actual fix, so if someone else has a better solution, I'd be interested to hear it.
I've browsed through the ant source code a bit and discovered that ant has a --launchdiag property which is helpful. Running with that gave me:
/local/apps/openJDK8/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64/bin/java -classpath /local/apps/ant/apache-ant-1.10.4/lib/ant-launcher.jar -Dant.home=/local/apps/ant/apache-ant-1.10.4 -Dant.library.dir=/local/apps/ant/apache-ant-1.10.4/lib org.apache.tools.ant.launch.Launcher --launchdiag
Launcher JAR= "/local/apps/ant/apache-ant-1.10.4/lib/ant-launcher.jar"
Launcher JAR directory= "/local/apps/ant/apache-ant-1.10.4/lib"
java.home= "/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/jre"
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/tools.jar
tools.jar= "null"
Setting "java.class.path" to "/local/apps/ant/apache-ant-1.10.4/lib/ant-launcher.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-antlr.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-swing.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-testutil.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-xalan2.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-junitlauncher.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-xz.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-junit.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-log4j.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-javamail.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-bsf.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-resolver.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-oro.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-bcel.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-jai.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-jsch.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-jmf.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-commons-logging.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-launcher.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-jdepend.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-commons-net.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-netrexx.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-junit4.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-regexp.jar"
Buildfile: build.xml does not exist!
Build failed
In the code I found that that java.home property comes from System.getProperty("java.home") which apparently is not the same thing as JAVA_HOME
By adding -Djava.home=$JAVA_HOME I was able to get it working

setting up classpath. javac is not recognized

I am trying to run my java program from command line.
I read an article about setting up classpath, but I get an error of javac is
not recognized as internal or external command. What should I do? (I dont want to set a permanent CLASSPATH)
This is what I have done in my command line
D:\user> set path=%path%;C:\Program Files\Java\1.7.0_07\bin
D:\user> cd testing
D:\user\testing> javac firstProgram.java
'javac' is not recognized as an internal or external command,
operable program or batch file.
Thank you
Assuming that the PATH is correct1, the most likely cause is that you have a JRE installation ... and a JRE doesn't include a java compiler. You need a JDK installation if you want to compile from the command line.
(You can confirm this by looking in the C:\Program Files\Java\1.7.0_07\bin directory to see if it contains a javac.exe file. A JRE won't ...)
Where can I find the Java compiler to download..
You need to download one of the JDK installers; see http://www.oracle.com/technetwork/java/javase/downloads/index.html
1 - I don't think quotes are required in a PATH variable on Windows. At least that's what various examples that Google found for me seem to imply. But I've never really understood the logic behind quoting in Windows ...
Its an issue related to Program Files.
First make sure that your JDK Folder is installed in Program Files or Program Files(x86) or any other folder.
Then you should use the path of bin folder in " ". Because command prompt does break the string at space. When you will write it in " " then it will take is as a whole String.
You try these commands
set path=%path%;"C:\Program Files\Java\1.7.0_07\bin"
or
set path=%path%;"C:\Program Files(x86)\Java\1.7.0_07\bin"
It might help you to get out of this.
Better do it in Environmental variable and check it!
try below command is recognized from command prompt
C:\Program Files\Java\1.7.0_07\bin\javac ab.java
This is just to verify your javac
Here's how you can set the path temporary, meaning if you close and reopen "command prompt" you will have to set the path again.
Assuming the path is C:\Program Files\Java\jdk1.6.0\bin
TYPE IN C:\Program Files\Java\jdk1.6.0\bin AND HIT ENTER
that's it.
The commands D:\user> set path=%path%;C:\Program Files\Java\1.7.0_07\bin works well for me
Adding few more information to this:
Please check the version of JDK and JRE installed on your computer. Recently I faced the same problem even after setting the PATH. It gives the error "javac - command is not recognised"
Solution is there must be similar versions of JDK as well as JRE
E.g.: JDK 1.7.75 along with JRE 1.7.75

'"java.exe"' is not recognized as an internal or external command,

I have downloaded both Java jdk1.7.0_06 and Java jre7. and i added the following system variable JAVA_HOME C:\Program Files\Java\jdk1.7.0_06\bin to my windows 7. But when I type the following in the CMD command line on my windows 7 C:\activiti-5.10\activiti-5.10\setup>ant demo.start to run a demo application I got the following error in the command line '
"java.exe"' is not recognized as an internal or external command, operable program or batch file
So does anyone know how i can solve this problem ?
BR
If you look at the "ant.bat" file, you will see that it looks for the "java" command in the following way:
If the %JAVACMD% environment variable is set, then it uses that.
Otherwise, if the %JAVA_HOME% environment variable is set, it tries to use %JAVA_HOME%\bin\java.exe
Otherwise, it tries to use java.exe; i.e. it will look on your %PATH%.
In your case, you have %JAVA_HOME% set ... but set to the Java installation's "bin" directory, not to the root of the installation. So the Ant.bat script looks in the wrong place for java.exe.
Just set %JAVA_HOME% correctly, and it should work.
JAVA_HOME C:\Program Files\Java\jdk1.7.0_06
As you can see from the above, you do not need to have the Java "bin" directory on your %PATH% for Ant to work, but it is a good idea to set it anyway. That way you can run the Java commands simply from the command line.
The setting of %CLASSPATH% is not relevant to this problem. Indeed, unless the build.xml file is broken, Ant will ignore your %CLASSPATH% environment variable.
You need to put the file java.exe in your PATH variable but the JRE in JAVA_HOME
JAVA_HOME is the path of JDK root folder.eg: C:\Program Files\Java\jdk1.7.0_06 but path define C:\Program Files\Java\jdk1.7.0_06\bin
JAVA_HOME C:\Program Files\Java\jdk1.7.0_06
JRE_HOME C:\Program Files\Java\jre1.7.0_06
path = C:\Program Files\Java\jdk1.7.0_06\bin;C:\Program Files\Java\jre1.7.0_06\bin
Typically JAVA_HOME should be the parent directory of the "bin" folder.(jre or jdk)
In this case ant expects the java to be from the JDK.
try following in a cmd window
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_06
set path="%JAVA_HOME%/bin;%path%;
ant
(side note: adding java.exe to path is not a requirement for ant; it is a convenience thing for the user)
Just delete the following set of files from your %windir/System32 folder. Actually deleting java.exe is enough but for consistency sake just delete all the java related binaries.
java.exe
javaw.exe
javaws.exe
Actually oracle windows installer places a copy of these files into %windir/System32 folder (which I don't understand why) but looks like they are not needed (as they are available anyway under JDK folder where you install them).
I have tried all the various solutions posted in the SO and other forums as well but none of them worked for me. I have also set all the relevant environment variables (JAVA_PATH, CLASS_PATH etc) correctly as well. Finally this is the only solution that has worked for me.
Go to the \squirrel-sql-3.9.0>squirrel-sql.bat .open that squirrel-sql.bat in Notepad and comment out the existing logic which is
=======================================
if exist "%IZPACK_JAVA%\bin\javaw.exe" (
set LOCAL_JAVA=%IZPACK_JAVA%\bin\javaw.exe
) else (
set LOCAL_JAVA=javaw.exe
)
echo Using java: %LOCAL_JAVA%
=================================
and add the below logic
#echo off
set LOCAL_JAVA=C:\Program Files (x86)\Java\jre7\bin\javaw.exe
echo Using java: %LOCAL_JAVA%
================================
make sure you add the correct path of javax.exe while adding above logic set LOCAL_JAVA=
and start the .bat file from CMD ..that's it. It should work. It worked for me.
I started getting this error in Android Studio after I updated it to version "Electric Eel".
It happened because Android Studio has changed where they put their JRE:
it used to be C:\Program Files\Android\Android Studio\jre
but now it is C:\Program Files\Android\Android Studio\jbr
To fix:
updated my JAVA_HOME environment variable to point to the new java location (C:\Program Files\Android\Android Studio\jre)
and then restarted Android Studio, and now it is fixed.
I agree with the above explanation but if the problem still persists try setting:
CLASSPATH = C:\Program Files\Java\jdk1.7.0_06\bin

"java -version" not working in command prompt

I downloaded this Java JDK and installed it.
But when I go to the command prompt to check the version, it says it's not recognized.
Is anyone else experiencing this issue with the latest Java?
I might not have installed the right version. I need the java that works with grails
C:\>java
'java' is not recognized as an internal or external command,
operable program or batch file.
C:\>java -version
'java' is not recognized as an internal or external command,
operable program or batch file.
C:\>
when i do a search on my computer for java, it does not find anything
Windows 2k8 R2 server-
For both java [-option] or %JAVA_HOME% to work in the command line you need the following:
In Control Panel->System and Security->System->Advanced system setting->Advanced->Environment Variables->System Variables
Edit the Path variable and add a ";" after the last value and add the the path to the Java bin directory:
e.g.- C:\Progra~2\Java\jre6\bin\
Add the JAVA_HOME Variable with the value set to the path for the java executable:
e.g.- C:\Progra~2\Java\jre6\bin\java.exe
Press simultaneously the "windows" and "pause" buttons on your keyboard, this will bring up the System Preferences dialog.
In the Advanced tab, find Environment Variables.
Then, in the User (upper) section, create or update the following two variables :
JAVA_HOME = where you put your JDK, eg. C:/Java/SDK
PATH = %JAVA_HOME%/bin
Close the dialogs.
Then, in a new command-line console, try "javac -version" and see if it's detected.
It's important that you use a new console, because environment variables are read only when the console is launched.
Java is typically installed (on Windows) as C:\Program Files\Java\jdk<version>
That installation directory has a subdirectory bin which you need to append to your PATH environment variable via the control panel. Then, the commands like java, javac etc. will be available on the command line.
BTW, the same is true for Grails.
Is the -version flag not recognized, or is the "java" command not recognized? One way to test this is just to type 'java' by itself and run it and see what happens.
If the command is not recognized, make sure that the JDK's install path is in your windows PATH. If not, you won't be able to use any of the java executables from the command prompt. Here's another link that may help out.
You need to manually add the path to javac.exe and java.exe to your operating system path. The Java installation program doesn't do that for you.
You most likely don't have java.exe in your system's PATH variable.
For Linux:
check $PATH and $JAVA_HOME. You can configure it in /etc/environment
From console you can check it like:
$ echo $PATH
For Windows:
My Computer -> Properties -> Advanced -> Environment Variables
Check there PATH.
From console you can check it like:
echo %PATH%
You should have a Java icon in Windows Control Panel. Locate the Java tab and click the View button. That will show you the path to the Java executables.
Last but not least, make sure you have restarted the computer so changes in the PATH variable can take effect.
You installed the JDK. Isn't java.exe part of the JRE? Do you have that installed?
Maybe your system variables in the environment variables are not set properly. Follow the steps in the link below. Finally, make sure the path component in system variables has only one JDK path. Delete other JDK paths that you won't use.
https://docs.oracle.com/javase/tutorial/essential/environment/paths.html
You might have installed a previous or older version of Java so you can just uninstall it and directly download JDK from Java JDK
I was also facing the same issue but when I downloaded and installed the latest version the issue was resolved.
Also uninstall any other Java versions which may be present in the program files.
To get to know other versions which may be present in your computer use Windows File Explorer to go to:
Files > Windows C > Program Files > Java
All the JDK and JRE you have will be listed there. Uninstall any other Java versions other than what you installed. And then make sure you have set the path variable of the JDK.
For me, it was incorrect line in the PATH
(1) Check PATH: Type "Edit System Environment Variables" on the search -> System Properties -> Advance -> Environment Variables -> System variables -> Path
(2) On the list, mine was C:\Program Files (x86)\Common Files\Oracle\Java\javapath so I just add \ at the end (the exe files in the javapath folder)
OS: Windows 10 64 bit
IF you set the PATH and it's not showing up in cmd when you run %PATH%, try restarting your computer.

Categories