Maven Installation - Environment Variables - java

I am using Maven for the first time on Windows 7 and getting this error:
ERROR: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "C:\Program Files\Java\jdk1.7.0_03\bin"
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation
Java version "1.6.0_29" Java(TM) SE Runtime Environment (build
1.6.0_29-b11) Java HotSpot(TM) Client VM (build 20.4-b02, mixed mode)
I've read everywhere online about how to set up the variables properly in windows for a Maven installation, also on this site, but, I can't seem to get my installation working.
Here's my set-up:
System Variables:
JAVA_HOME
C:\Program Files\Java\jdk1.7.0_03\bin
Path
C:\apache-maven\src\bin
Any help would be greatly appreciated.

thats because your JAVA_HOME is incorrect
set JAVA_HOME to C:\Program Files\Java\jdk1.7.0_03
also some systems , maven might still throw error because if the path to Java Directory has space i.e Space between Program and Files in the path
You might as well move the java to someother path without space
instead of
C:\Program Files\Java\jdk1.7.0_03
to
C:\Java\jdk1.7.0_03
Edit
Double-quoting the value of JAVA_HOME can also cause this problem
set JAVA_HOME="C:\Program Files\Java\jdk1.6.0"
doesn't work for me, but this does:
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0

set JAVA_HOME to C:\Program Files\Java\jdk1.7.0_03 (without bin)

For environment variable of JAVA_HOME should be like this "C:\Program Files\Java\jdk1.7.0_03\" without bin. Please note that likely you have 2 version of Java installed. Make sure which one that you want to use.

Seemed it was a problem with the latest version of Maven. I used Maven 2.2.1 with the same set-up and it run with no problems.

JAVA_HOME should be like this C:\PROGRA~1\Java\jdk1.7.0_03
Hope this will work!

Related

Getting different version for java and javac

Before marking it duplicate FYI I have already read How can I change the Java Runtime Version on Windows (7)? and How to set path for Jre 6 when jre 7 installed?.
I have both Java7 and Java8 in my machine. I have
JAVA_HOME = C:\Program Files\Java\jdk1.7.0_60
PATH = ...;%JAVA_HOME%\bin;....
but I am getting
C:\>java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
C:\>javac -version
javac 1.7.0_60
I want to set JRE to 1.7 too. How to do that?
You will probably have to edit your path environment variable.
If you want to check what's in your PATH environment variable in an organized fashion, run:
echo %path:;=&echo.%
Make sure the 1.8 is not on the path or if you want it there make sure it appears after 1.7.
To edit it, go to My Computer > Properties > System Properties > Advanced tab > Advanced section > Environment Variables.
Also check what is actually launched when you run java from the command line, run the following command:
where java
It will show you what windows runs when you request java.
To solve the problem, remove or change the name of java.exe and javaw.exe into System32 folder:
Prepend the System Variable's Path with JRE bin's path.
where java did work for me. I found there is another version of java associated with the SPSS (1.8.0). Uninstall SPSS and the problem solved.
The solution that worked for me was:
In "Path" variable replace "C:\ProgramData\Oracle\Java\javapath;" with %JAVA_HOME%\bin where JAVA_HOME variable was set to "C:\Program Files\Java\jdk1.7.0_60"

JDK error when trying to start Android Studio

I have just switched from Windows7 to Windows8.1 and I'm having trouble making Android Studio work now.
I have installed Android Studio and the JDK. First I tried it out with the latest versions Android Studio v.0.8.14 and JDK 1.8, but I could not get it to work. I then tried to use the versions I used on my previous Windows7, and installed Android Studio 0.8.2 and JDK 1.7.0_67, but I still can't get it to work.
The error I'm getting is:
Failed to load JVM DLL C:\Program Files\Java\jdk1.7.0_67\jre. If you
already have a 64-bit JDK installed, define JAVA_HOME variable in
Computer > System Properties > System Settings > Environment
Variables
I have set JAVA_HOME to my JDK path. I've tried to add \bin to that path, which didn't help. I've tried to add the JDK_HOME variable and set path to it, which didn't help either. I have also added "C:\Program Files\Java\jdk1.7.0_67\" to my PATH variable, which also didn't help. I tried editing studio.bat adding a string to point to my JDK folder, which also didn't work.
When I check my Java from console (cmd) I get the msg that it works find:
C:\Users\Igor>java -version java version "1.7.0_67" Java(TM) SE
Runtime Environment (build 1.7.0_67-b01) Java HotSpot(TM) 64-Bit
Server VM (build 24.65-b04, mixed mode)
Is Windows 8.1 the problem? Do I have to do something different on it?
Follow these steps:
Control Panel>>System>>Advanced(tab)>>Environment Variables>>System Variables
New
Variable name: _JAVA_OPTIONS
Variable value: -Xmx512M
I had exactly the similar problem:
failed to create JVM: error code -6
JVM PATH: .............
If you already have a 64-bit JDK installed, define a JAVA_HOME variable in Computer > System Properties > System Settings> Environment Variables.
Note: Do *not* choose a Java "JRE". You need to point to a full JDK, otherwise the IDE may fail to start. See http://tools.android.com/knownissues for more details.
Solution for me
I solved it with the help of Rahul Wadhai:
1) Go to C:\users\<your_user>.AndroidStudio2.2\ and open studio.vmoptions
2) change -Xmx and XX:MaxPermSize to lower values(then you have currently) and try to run AS again. ( If it does, then you can increase the values back. )
3) If it doesnt help, then try to rename .AndroidStudioX.X and then open AS again.
4) If it doesnt help, then you can search the problem within this android folder (using TextCrawler) , maybe somewhere in config files, there needed to change something. And then you can import settings from old folder.
You need to mention the JDK folder path in the Environment variable:
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_51
Don't use build number coming in cmd.
To get this working, I put my JDK path in the Path variable as the first item. For some reason, when it's the last item it does not work.
You have to create a new variable in the System variable named JAVA_HOME = "C:\Program Files\Java\jdk1.7.0_67", in your PATH variable.
I tweaked the studio.vmoptions file when I followed a method in making it run faster and it stopped working showing the same JDK error.. I did most of the fix mentioned above and none worked for me. What worked for me though was deleting the studio.vmoptions file and everything was great again.
Go to your c:\ users\yourcomputername\ for example .AndroidStudio1.5
You will see config and system folder in it then delete the .AndroidStudio1.5 using it as example .
Go and relaunch the studio64
This is the solution that worked for me after many frustrated attempts:
go to the folder C:\program files\Android\Android Studio\bin
rename the file 'studio.64' to 'studio.bat' and run this file.

How to install Apache Ant on Windows 7

I want to install Apache ant on windows. Here is some information below:
http://ant.apache.org/manual/install.html
Error installing Ant: ANT_HOME is set incorrectly
I followed its descriptions and step by step but it still cannot work.
I think the entire environment variables I set are correct. May please someone helps me? And some copies from cmd.
C:\>echo %ANT_HOME%
C:\Program Files\apache-ant-1.9.4
C:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.6.0_34
C:\>java -version
java version "1.6.0_34"
Java(TM) SE Runtime Environment (build 1.6.0_34-b04)
Java HotSpot(TM) Client VM (build 20.9-b04, mixed mode, sharing)
C:\>ant
is not recognized as an internal or external command,operable program or batch file.
My Ant version is 1.9.4
I think the path is not set properly.
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0
set ANT_HOME=D:\software\apache-ant-1.9.4
set PATH=%PATH%;%JAVA_HOME%\bin;%ANT_HOME%\bin
Edit: fixed PATH definition
Change your path From:
C:\Program Files\apache-ant-1.9.4
C:\Program Files\Java\jdk1.6.0_34
To:
C:\Progra~1\apache-ant-1.9.4
C:\Progra~1\Java\jdk1.6.0_34
When setting the paths.
Change you path , not install on C:\Program Files\
Add Path, like:
set PATH=%PATH%;%JAVA_HOME%\bin;%ANT_HOME%\bin

Two installed javas on same pc. The one with lower version can not be called

I have two javas installed on my pc. jdk1.7.0_45 (x64) and jdk1.6.0_45(x86). I want that default java on my machine would be jdk1.6.0_45(x86). I added JAVA_HOME with value C:\Program Files (x86)\Java\jdk1.6.0_45 and added C:\Program Files (x86)\Java\jdk1.6.0_45\bin to system path, but still when i type in command prompt "java -version" it says:
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
I have no idea why the things are like that, because my OS should see jdk1.7.0_45 (x64) version. Why is that so?
I use windows 8
edit:
after setting java home to jdk1.7.0_45 (x64) folder and updating path accordingly javac works, but then I set java home and path to jdk1.6.0_45(x86) javac does not work.
You need to add the %JAVA_HOME%\bin to the very beginning of your path. This is because Java is installed in your %SystemRoot%\system32, too. If you add the %JAVA_HOME%\bin to the beginning of your path the Java installed in your JAVA_HOME will be used.
JAVA_HOME does not help when we run java from command line, you should fix PATH system var
I added JAVA_HOME with value C:\Program Files (x86)\Java\jdk1.6.0_45
In Windows, you should excape spaces in the path: JAVA_HOME="C:\Program Files (x86)\Java\jdk1.6.0_45". But the best way is to set Java to a folder that doesn't have spaces in its path. For example, I use C:\Java\Java6
and added C:\Program Files (x86)\Java\jdk1.6.0_45\bin to system path
Probably you added after path to the Java 7. Make sure that Java 7 doesn't exist in the system path.

java -version doesn't display the value of JAVA_HOME

I've installed jdk 7 and set up the "JAVA_HOME" to this version. Then, I've installed jdk 6 and I've updated the "JAVA_HOME" to point to jdk 6. After closing and reopening the system, when typing "java -version", I got always :
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) Client VM (build 24.0-b56, mixed mode, sharing)
However, when typing
echo %JAVA_HOME%
I got :
C:\Program Files\Java\jdk1.6.0_45
I didn't understand why java -version don't display the value of "JAVA_HOME"
Java 7 puts a java.exe in c:\windows\system32. You could try to delete these exe's, but I'm not sure Windows will allow it, or restore it after a reboot.
If you want to override it, you must put %JAVA_HOME%\bin as first entry in your PATH, before c:\windows\system32.
Which java starts when you run java -version depends on the PATH env variable, not JAVA_HOME. OS will be looking for java.exe (Windows) like for any other program
if you run java on your command window, it takes java from the PATH variable. JAVA_HOME is used my maven etc...
I believe your PATH variable is pointing to JAVA version 1.7.0_40/bin directory.
According to my understanding, this is nothing to do with your JAVA_HOME environment variable. You are getting java version from C:\windows\system32\java.exe.
If you don’t want that behaviour then in system variables section put %JAVA_HOME%\bin as starting element (Of course you should have JAVA_HOME). (I thought of adding image but I dont have enough reputation to do so :( )

Categories