mvn --version not working? - java

I have problem with MAVEN path
i have already set all the path but not working please see the below path
Path
....;C:\Program Files\Java\jdk1.6.0_20\bin;D:\apache-maven-3.2.1\bin
JAVA_HOME
C:\Program Files\Java\jdk1.6.0_20
MAVEN_HOME
D:\apache-maven-3.2.1
When i try to run mvn --version it will give error of JAVA_HOME please see the error
Error: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "C:\Program Files\Java\jdk1.6.0_20\bin"
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
But javac is working fine

JAVA_HOME needs to point to the folder which contains bin/, lib/, etc.
Your variable points inside of Java's home folder.

Change JAVA_HOME C:\Program Files\Java\jdk1.6.0_20\bin to C:\Program Files\Java\jdk1.6.0_20.
PATH and JAVA_HOME are two different things:
With PATH you tell the system where to search for commands. There you should have
PATH=...;C:\Program Files\Java\jdk1.6.0_20\bin;
With JAVA_HOME you define where your Java has been installed. Applications using JAVA_HOME add the bin and/or lib directories. There you should have
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20
Try the following in a DOS-Box:
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20
set MAVEN_HOME=D:\apache-maven-3.2.1
set PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin
mvn --version

Once you have identified the JRE installation path:
Right-click the My Computer icon on your desktop and select Properties.
Click the Advanced tab.
Click the Environment Variables button.
Under System Variables, click New.
Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit.
If your Java installation directory has a space in its path name, you should use the shortened path name (e.g. C:\Progra~1\Java\jre6) in the environment variable instead.
Icon
Note for Windows users on 64-bit systems
Progra~1 = 'Program Files'
Progra~2 = 'Program Files(x86)'
Click OK.
Click Apply Changes.
Close any command window which was open before you made these changes, and open a new command window. There is no way to reload environment variables from an active command prompt. If the changes do not take effect even after reopening the command window, restart Windows.
If you are running the Confluence EAR/WAR distribution, rather than the regular Confluence distribution, you may need to restart your application server.

You required to set or make sure about 3 variables environment behaviour:
1. M2_HOME: set this environment variable to point out to apache maven directory. Note: must not be point to bin directory.
JAVA_HOME: This environment variable must be point to jdk folder, not include bin directory.
path: your system/user path variable must be pointing to bin directory of java environment.
this works fine for me.

first set all these things
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20
set MAVEN_HOME=D:\apache-maven-3.2.1
set PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin
check
mvn --version
if still not working then delete path in environment variables again create it as
PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin
close previously opened cmd prompt
open new cmd
and check
mvn --version

Related

JAVA_HOME IS INVALID (Cordova)

As-salāmu ʿalaykum,
I'm having trouble setting JAVA_HOME correctly.
I know that the JAVA_HOME needs to be set to C:\Program Files\Java\jdk1.8.0_92
I know PATH has to be set toC:\Program Files\Java\jdk1.8.0_92\bin
I set both the JAVA_HOME and PATH as a user variable and as a system variable.
When I run Android Studio tells me it's invalid. When I echo out JAVA_HOME, it's set as expected. Any ideas?
You need to set your JAVA_HOME to: C:\Program Files\Java\jdk1.8.0_92\
And set PATH to: C:\Program Files\Java\jdk1.8.0_92\bin so that it can be accessible from cmd
Then you might need to restart the computer
Note:
In some cases JAVA_HOME is specified differently somewhere else such as gradle.properties file. In that case, the global value can be overridden by the project's JAVA_HOME for that specific project.
You didn't mention which windows version you are working on. However, you can try to set the JAVA_HOME variable via the command line as an alternate solution.
Open Command Prompt (make sure you Run as administrator so you're able to add a system environment variable).
Set the value of the environment variable to your JDK (or JRE) installation path as follows:
setx -m JAVA_HOME "C:\Progra~1\Java\jdk1.8.0_XX"
If the path contains spaces, use the shortened path name.
Restart Command Prompt to reload the environment variables then use the following command to check the it's been added correctly.
echo %JAVA_HOME%
You should see the path to your JDK (or JRE) installation.
Besides defining the path you need to enable Java in Windows Defender.
Hint: Disable windows defender and firewall (google it).
Put in the prompt "java -version" and "javac -version" commands again and have fun.
Sorry, english isn’t my first language.

Setting JAVA_HOME variable

I try to set JAVA_HOME variable on an ubuntu server. I get the Java path with this command
which java
/usr/bin/java
I set the result in /etc/environment
JAVA_HOME="/usr/bin/java"
When I try to run a mvn command I get this error
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/bin/java/bin/java
You should not set JAVA_HOME to /usr/bin/java, because that's just a symbolic link to the java executable, which points to where the real executable is.
JAVA_HOME should point to the Java installation directory, and not to the java executable (or a link to the executable).
Find out where your Java installation directory is and then set JAVA_HOME to that directory (and not to the java executable). If you installed Java using Ubuntu's package management system, then the Java home directory is probably one of the subdirectories in /usr/lib/jvm.
Per the Oracle site:
export JAVA_HOME=jdk-install-location
export PATH=$JAVA_HOME/bin:$PATH
You can add these lines into your ~/.bash_profile (or ~/.bashrc), and then refresh using source ~/.bash_profile

Apache maven not working in cmd

Recently I downloaded the apache maven 3.3.9 zip and extracted it to my D:\ directory but when I run mvn -version or mvn in cmd sometimes it gives me the error mvn is not an internal or external command and sometimes JAVA_HOME is not set properly. However I checked by echo %JAVA_HOME% that it points to the right location of my jdk which is in my C:\ directory. I also inserted variables in user and environment variables. I run cmd as administrator. I have tried almost everything but nothing works. Can anyone please tell me how to fix this problem? It would be really appreciated. Thanks.
Open command line, type "set" and hit enter, it will give you list of environment variables. Search for M2_HOME and JAVA_HOME. If they don't exist then you need to right click My Computer--> Properties --> Advanced --> Environment variables. Add M2_HOME and JAVA_HOME environment variables there.
First, add JAVA_HOME, you need to click on User variables, add new variable and set it to your java directory, for example: "C:\Program Files\Java\jdk1.7.0_75"
Then add Java compiler location to System Path by clicking System Variables, choose Path, click edit and set it to java directory on your system. Make sure that path to compiler location ends with "/bin", like here: "C:\Program Files\Java\jdk1.7.0_75\bin"
To add M2_HOME do the same, set it to your location, for example: "C:\Program Files\Apache Software Foundation\apache-maven-3.3.3".
When you done, verify it on command line: mvn --version
The mvn executable has to be added to your PATH variable. Alternatively you can try starting mvn from its bin-directory as a first test.
This explains everything.

Should I add both JAVA_HOME and JRE_HOME in environmental variable, PATH?

I ran into this error while setting up my Tomcat and Java environmental path:
Neither the JAVA_HOME nor the JRE_HOME environmental variables is
defined. At least one of the 2 environmental variables is needed to
run this program.
In the user variables: I created JAVA_HOME variables and add C:\Program Files\Java\jdk1.8.0_25 to its path. and then did an edit of system variable PATH, added C:\Program Files\Java\jdk1.8.0_25; to the beginning of the its path.
I also created JRE_HOME in user variable and added C:\Program Files\Java\jre1.8.0_25 to its path.
Is it necessary to create JRE_HOME and should I add the JRE path to the system variable also?
This answer explains all the steps with screenshots and examples
Better Use the 8.3 directory-format. In fact No spaces, ever.
JAVA_HOME - your JDK folder
C:\Program Files\Java\jdk1.6.0_45 == C:\PROGRA~1\Java\JDK16~1.0_4
C:\Program Files\Java\jdk1.7.0_71 == C:\PROGRA~1\Java\JDK17~1.0_7
C:\Program Files\Java\jdk1.8.0_25 == C:\PROGRA~1\Java\JDK18~1.0_2
C:\Program Files\Java\jdk1.9.0 == C:\PROGRA~1\Java\JDK19~1.0
JRE_HOME
C:\Program Files\Java\jre6 == C:\PROGRA~1\Java\jre6
C:\Program Files\Java\jre7 == C:\PROGRA~1\Java\jre7
C:\Program Files\Java\jre1.8.0_25 == C:\PROGRA~1\Java\JRE18~1.0_2
C:\Program Files\Java\jre1.9.0 == C:\PROGRA~1\Java\JRE19~1.0
Addition to PATH - best practice!
USE WINDOWS+R
Enter C:\Windows\system32\systempropertiesadvanced.exe
Add ;C:\ProgramData\Oracle\Java\javapath; to the end of PATH
(System Variables not User Variables).
Click OK, explore to C:\ProgramData\Oracle\Java\ and rename javapath folder (from C:\ProgramData\Oracle\Java\javapath\) to javapath_old.
Create new folder named javapath.
Start CMD and browse into (the now empty) C:\ProgramData\Oracle\Java\javapath\.
Run to create symbolic links:
ln -s "C:\Program Files\Java\jre7\bin\java.exe" java.exe
ln -s "C:\Program Files\Java\jre7\bin\javaw.exe" javaw.exe
ln -s "C:\Program Files\Java\jre7\bin\javaws.exe" javaws.exe
Done with PATH and *_HOME, now let's continue with the Windows Registry.
Open up you preferred registry editor (Registry Workshop is the best), browse HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit notice all installed versions are shown as keys, double click CurrentVersion (REG_SZ value) and modify its data to your preferred SDK version, mine is 1.7 (For Android Studio)
Do the same for HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment (with CurrentVersion)
Close down java-based programs such as eclipse or IntelliJ,
Open up task-manager- processes tab,
Look for explorer.exe, cmd.exe and java(*something*).exe programs,
Right-click eache and click End Task (not "End Process-Tree"!)
Click File➩New Task➩enter explorer.exe.
The changes you've done above were applied successfully
No need to reboot, no need to log-off/on again.
You really do not need to add JRE_HOME to the system variables. Tomcat looks for JAVA_HOME or JRE_HOME to get itself start. This is because tomcat require some java library to get itself started. Tomcat will provide additional debugging functionality if Jdk is provided instead of Jre. Additional details here
Adding {JAVA_HOME_DIR}/bin to your path would enable to access java from anywhere.
After modifying system variables , it is important to open new console window
Try this...
For Java,
In the User variables, add PATH value is C:\Program Files\Java\jdk1.8.0_25\bin;
For Tomcat
In the System variables, add JAVA_HOME value is C:\Program Files\Java\jdk1.8.0_25
Now classpath has been set to your machine. You can access java from anywhere in your machine.
After Done this, Go to Command Prompt and go to ApacheTomcat*x.x and move to bin folder,,
Start the Server
startup.bat
For check Tomcat running status, Go to your browser, and Paste the URL,
http://localhost:8080/
Stop the Server
shutdown.bat

"The system cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe"

I am on JDK 8u25 on Windows 8, and I am experiencing a problem with my Java installation. I can run javac perfectly fine, but running java produces this error message:
The system cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe
How do I fix this?
I think the problem has to do with my environment variables.
The important variables, as I have set them, are:
JAVA_HOME – C:\Program Files\Java\jdk1.8.0_25
CLASSPATH – .;%JAVA_HOME%\lib
PATH – <other paths omitted>;%JAVA_HOME%\bin
And their expansions, as viewed with set in cmd, are:
JAVA_HOME – C:\Program Files\Java\jdk1.8.0_25
CLASSPATH – .;C:\Program Files\Java\jdk1.8.0_25\lib;%CLASSPATH%;
PATH – C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.6.0_45\bin;<other paths omitted>;C:\Program Files\Java\jdk1.8.0_25\bin
The full output of set can be viewed here.
I've got a similar problem I'm currently working on solving. I can't say this will solve your error since there may be issues with other software (which is my case with Eclipse Luna).
Java is using the path given in your PATH variable, which is,
C:\ProgramData\Oracle\Java\javapath
Go to this folder (ProgramData is hidden, so unhide it if necessary) and right click on the java.exe symlink. You'll see in the Target field where it's looking for java.exe. It may be pointing to the java.exe file from your previous jdk1.6.0_45 install. Either paste in new shortcuts here or change the PATH setting as others have mentioned.
I've found that the Java installer doesn't change the javapath or update the system path, at least when going from 1.8 to 1.7. In my case changing the shortcuts only led to a problem with Eclipse on startup.
EDIT:-----
After playing with javapath folder shortcuts it turns out you need symlinks, at least for Eclipse. See, Windows how to create directory symlink.
You don't need the /d switch for a file symlink,
mklink java.exe "C:\Program Files\Java\jdk1.8.0_20\bin\java.exe"
mklink javaw.exe "C:\Program Files\Java\jdk1.8.0_20\bin\javaw.exe"
mklink javaws.exe "C:\Program Files\Java\jdk1.8.0_20\bin\javaws.exe"
This now works for me.
Why Oracle did such a poor way to point to java is beyond me. We solved this problem by creating a new link to the JDK
mklink /d C:\ProgramData\Oracle\Java\javapath "C:\Program Files\Java\jdk1.8.0_40\bin\"
The same would work for a JRE if that is all that is required.
This replaces the old symlinks in C:\ProgramData\Oracle\Java\javapath (if they existed previously)
I had in PATH:
C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.8.0_92\bin;<others omitted>
I removed:
C:\ProgramData\Oracle\Java\javapath;
and that fixed the issue for me. java -version now gives details about the Java version, etc.
This will solve all problems relating to Java and environment variables:
Make your way to Windows' Environment Variables dialog.
Under System variables, select the variable named Path. Click Edit...
Remove the entry that looks like:
C:\ProgramData\Oracle\Java\javapath
Add the path of your JDK/JRE's bin folder.
Don't forget to set JAVA_HOME.
I got same error while running JAVA command. To resolve this, I moved the java path as the first entry in the path, and it resolved the issue. Please have look at this screenshot for reference:
Updating the PATH Environment Variable
If you do not set the PATH variable, you need to specify the full path to the executable file every time you run it, such as:
C:\> "C:\Program Files\Java\jdk1.8.0\bin\javac" MyClass.java
It is useful to set the PATH variable permanently so it will persist after rebooting.
To set the PATH variable permanently, add the full path of the jdk1.8.0\bin directory to the PATH variable. Typically, this full path looks something like
C:\Program Files\Java\jdk1.8.0\bin. Set the PATH variable as follows on Microsoft Windows:
Click Start, then Control Panel, then System.
Click Advanced, then Environment Variables.
Add the location of the bin folder of the JDK installation to the PATH variable in System Variables.
The following is a typical value for the PATH variable:
C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.8.0\bin
Note:
The PATH environment variable is a series of directories separated by semicolons (;) and is not case-sensitive. Microsoft Windows looks for programs in the PATH directories in order, from left to right.
You should only have one bin directory for a JDK in the path at a time. Those following the first instance are ignored.
If you are not sure where to add the JDK path, append it.
The new path takes effect in each new command window you open after setting the PATH variable.
There are 2 versions of jdk in your PATH VARIABLE jdk1.6.0_45 and jdk1.8.0_25. Try removing the first one ie. jdk1.6.0_45 from the PATH
If you're on a corporate PC that's fairly restricted by group policy, this might work....
Assuming that
your Windows PATH includes C:\ProgramData\Oracle\Java\javapath
you have JDK installed to C:\Program Files\Java\jdk1.8.0_60\bin
Then create the following text file mklink.bat and put it on your desktop:
rem mklink.bat
mklink /d C:\ProgramData\Oracle\Java\javapath "C:\Program Files\Java\jdk1.8.0_60\bin"
pause
Now right-click it and choose "Run as Administrator". Provide admin credentials. The script should report success. Now you can compile or run Java.
This usually happens when you update the java,
the easiest way to solve this is to just uninstall the JDK & then reinstall it.
NOTE: This doesnt remove the path or classpath so no need to worry.
Uninstall all JDKs installed on your computer from the Java Control Panel
Search for C:\ProgramData\Oracle\Java and delete that directory and all files contained within. You can do this from the command line using rmdir /S C:\ProgramData\Oracle\Java
Then search for C:\ProgramData\Oracle and delete the oracle folder. You can do this using rmdir /S C:\ProgramData\Oracle
Now install JDK and set the path.
Run the program.You won't find the same problem anymore.
This problem exists when you upgrade from one version to another.because jdk is not automatically upgraded.
For the same you can change the environmental varibles.
In system variables look for the PATH and add the jdk bin location in the front of the string(not at the back).
Once you have done that check in CMD if "java" and "javac" works.
if it works, again go to system variables.
add "CLASSPATH" A the variable and set value " .
c:\Program Files\Java\jdk1.8.0_91\lib;"
There must be two or more PATH variables. Try merging all of them into one using semi-colon (;)
I got the same after installing java8 from a non-permissioned account.
To fix I simply reinstalled from admin user account.
This created the quoted directory with file links to java exes.
I had also similar problem where by I had to un-install JDK 1.8 and needed jdk 1.7.
What i did was removed the symbolic links from the javapath and then imported the shortcuts of java, javaw, javaws from the bin directory to the javapath folder. However, I found some permission issues in the enterprise laptop where by I did not have the privilege to modify/ update this directory. I had given appropriate permission from the administrator and there by resolved it.
c:\ProgramData\Java\javapath is used for symlinks. You can of course add the full path to your Java Path to %PATH%, but equally you can create a symlink to the path to the above location.
Open CMD as Administrator.
Type mklink java.exe (full path to your Java.exe)
eg
mklink java.exe "C:\Program Files\Java\jdk1.8.0_25\bin\java.exe"
Don't worry.
Just uninstall jdk as well as jdk updates
Before re installing jdk ,delete the oracle folder inside programData hidden folder in C:\
Then reinstall.
Set the following,
JAVA_HOME
CLASSPATH
PATH
JRE_HOME ( is optional)
Please remove "C:\ProgramData\Oracle\Java\javapath\java.exe" from the Path variable and add your jdk bin path. It will work.
In my case the I have removed the the above path and added my JDK path which is "C:\Program Files\Java\jdk1.8.0_221\bin"
For New version of Java JavaPath folder is located
64 bit OS
"C:\Program Files \Common Files\Oracle\Java\javapath\"
X86
"C:\Program Files(x86) \Common Files\Oracle\Java\javapath\"
This will solve all problems relating to Java and environment variables:
Make your way to Windows' Environment Variables dialog.
Under System variables, select the variable named Path. Click Edit...
Remove the entry that looks like:
C:\ProgramData\Oracle\Java\javapath
Add the path of your JDK/JRE's bin folder.
Don't forget to set JAVA_HOME.
This helped me.......:-)
For me it worked like this:
On your desktop go to Search->View advanced system settings->Environment Variables
Under System Variables look for path and click Edit.
Click on New and add the new Path and move it to the top.
To find your java path if you don't know where it is installed in cmd type where javac
<>\Common Files\Oracle\Java\javapath\ is now created as a junction, no symlinks anymore

Categories