libgdx not using correct JAVA_HOME path - java

I know there are plenty of questions on JAVA_HOME and I've certainly worked through it before. I've been setting up and running java code for years.
It's my understanding that libgdx needs a path to a jdk bin, rather than a jre bin. When I tried to create a little test file, I received the following error:
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jre7\bin
The invalid directory points to a jre bin, so I downloaded a jdk and added its path to my environment variables, separated by a semicolon.
C:\Program Files\Java\jdk1.7.0_40\bin;C:\Program Files\Java\jre7\bin
but when I ran libgdx again, I got the same error. After restarting my computer to no avail, I tried checking my command prompt manually for all my environment variables. While my Computer > Properties > Advanced System Settings > Environment Variables path was still set to include both directories, the cmd prompt told a different story.
JAVA_HOME=C:\Program Files\Java\jre7\bin
JRE_HOME=C:\Program Files\Java\jre7\bin
So I tried manually setting these values to change them to what they should be. First (having not seen JRE_HOME as a separate variable) I added a semicolon and the jdk path to JAVA_HOME to make it match what was in my GUI environment variables path. When that failed, I separated them like so
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_40\bin
JRE_HOME=C:\Program Files\Java\jre7\bin
Which also has not helped my problem. The error message has not changed. I'm not quite sure what else to do at this point and no other online source seems to answer this particular problem. Hopefully the fine folks at stack are up to the challenge!
Thank you!

I had the same problem too. You need to remove \bin. Also, if you change the JAVA_HOME environment variable, you'll need to restart the Libgdx Project Generator, otherwise it will not use the latest variable value.
You'll only have to include \bin inside the PATH variable.

Make sure your JAVA_HOME environment variable does not contain a semi-colon at the end of the path.
libGDX also specifies a JAVA_EXE variable. To do this they append the JAVA_HOME variable to include '/bin/java.exe'. This can be seen in the code below:
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
The full code can be reviewed on GitHub here.
Keeping the above information in mind, change your JAVA_HOME variable to point to the JDK version of Java you have installed:
C:\Program Files\Java\jdk1.7.0_40
It is not necessary to include the bin folder in your JAVA_HOME variable as libGDX does this for you.

Related

"Javac" doesn't work correctly on Windows 10

the problem is that I upgraded to Windows 10 and now I'm installing my tools to programming and now that I installed the JDK 7 of Java, when I try to use in the cmd the command:
- "javac"
The result of this is: "javac" is not recognized as an internal or external command...
But I was edited the PATH with the correct link of jdk, because when I use "java", it is ok.
Now, I tried in the console with this command: PATH=%PATH%;"C:\Program Files\Java\jdk1.7.0_79\bin"
And when I executed the command "javac" it works, but now, when I open other console, it doesn't work, or when I restart the console, this command is not recognized.
What could be the problem?
java is part of the JRE, not the JDK.
You need to add the JDK bin to the system PATH, in
"Control Panel" | System | Advanced | "Environment Variables"
Her's how I configure System variable on Windows 10 :
I am totally new to java and spent hours trying to get the problems with PATH and CLASSPATH worked out. There was one person who said to restart the command prompt after you modify the environment variables; that was it for me. While you are testing different configurations, make sure to relaunch the command prompt before testing. It seems like there are at least 2 different ways of setting this up. I went with the following:
1) In System Variables, add
JAVA_HOME = c:\program files (x86)\java\jdk1.8.0_121
2) In System Variables, add the following to existing Path...
%JAVA_HOME%\bin
That's it.
No need for quotes around anything. No double forward slashes or anything else. I think it would also work if I removed the java_home variable and just listed the explicit path to bin in the PATH variable, but I'm not touching it again now that it finally works.
After adding C:\Program Files\Java\jdk1.8.0_73\bin to the system variables I turned off my command prompt and opened another one. Then it worked.
Maybe a bit late, but i had same problem.
Click on "Move up" button for Java path and move it at top.
It fixed problem for me
just add C:\Program Files\Java\jdk1.7.0_80\bin as the path in environmental variables. no need to add java.exe and javac.exe to that path. IT WORKS
I added below Path in environment variable
;%JAVA_HOME%/bin instead of %JAVA_HOME%\bin
in my case , it fix the problem
I had the same issue on Windows 10 - the java -version command was working but javac -version was not. There are three things I did:
(1) I downloaded the latest jdk (not the jre) and installed it. Then, I added the jdk/bin path tan o environment variable. In my case, it was C:\Program Files\Java\jdk-10\bin. I did not need to add the ; for Windows 10.
(2) Move this path to the top of all the other paths.
(3) Delete any other Java paths that might exist.
Test the java -version and javac -version commands again. Voila!
For some reason it worked for me to add quotation marks to the path folder on windows 10. not C:\Program Files\Java\jdk 1.8.0_111\bin, but "C:\Program Files\Java\jdk 1.8.0_111\bin".
now i got it finally! make sure that there are no spaces before and after the path and put the semi-colon on both sides without spaces
The PATH is for current user, instead you can add a CLASSPATH and below link would help you more PATH and CLASSPATH
I added below Path in environment variable
C:\Program Files\Java\jdk1.8.0_91\bin
and then compiled the program but got the error then I restarted the system and again compiled the program
This time it worked :)
Add java path to environment variables and move it to the top of all the paths available there. It worked for me.
To be sure about your path, you can use double quotes " to locate the path or if you are in Windows, you can browse to path to select "C:\Program Files\Java\jdk1.8.0_121\bin" folder.
in the search window type 'environment variables' this should give you a link to editing the variables. On the variables editing page there is an upper section and a lower section in the lower section add NEW,type path C:\Program Files\Java\jdk-10\bin this worked great for me and it finds the compiler all the time.
Kind of beating a dead horse now but, I want to clarify one thing that may not be quite so obvious. Yes indeed you need to edit the PATH environment variable as already stated many times. The key for me was to edit the PATH under SYSTEM variables. I had inadvertently edited the PATH under USER variables. Why did this matter? On my machine I have to log in as an Administrator to edit environment variables. So editing the User variables was not helping because I run the command prompt under my login (non-admin) account. Grrr!
Also, I found that closing the command prompt window, and re-opening it after the PATH variable update was required. Changing the order of the values, adding semi-colons, etc. didn't make a difference for me.
Cheers
If you have set all PATH variables correctly after installation, just restart it.
I had the same problem, I had also installed new Windows7 OS then I upgraded it to Win 10. Then i started setup necessary tools like IntelliJ, Java jdk,jre, eclipse so on.
In cmd, java -version worked but javac compiler got unrecognized. I checked and all good, the files in the folders, path are correct and so on.
I restarted and checked it again in cmd ,it worked.
what I did is:
I typed ; accidentally in front in the path variable and then hit OK, after this if I again edit it was nowhere going to the same page as earlier, it opened a new page as defined for user variables and then I was able to remove double quotes in front of the PATH VARIABLE.
Everything worked fine then. :)
Did it just now.
Add
PATH = C:\Program Files\Java\jdk1.8.0_66\bin
in Advanced system setting. Then Choose Environment Variable.
for windows 10 Users Use Java path( JDK Bin location) AS "C:\Program Files\Java\jdk-9.0.1\bin" it will work.
Points to remember, do as the image shows. Move the highlighted bar up using move up button, this will help.

setting issue of JAVA_HOME and JAVA_PATH

I have been using Eclipse to develop java program on a windows 7 machine. It works. I also typed "java" from the command prompt, it also shows the help message. In other words, I think Java was correctly installed on this machine. However, when I open the "environmental variable" setting on this machine, I cannot find either "JAVA_HOME" setting and "JAVA PATH" setting. What is the problem of this?
Java also copies java.exe and javaw.exe under C:\Windows\System32, there's where your java is running from.
You can confirm that by using where commmand:
On my win7 machine:
>where java.exe
C:\Windows\System32\java.exe
Some environment variables are defined at machine level and some are defined (and overwritten) at user account level. Just do following in windows cmd prompt:
c:\echo %PATH% or just type c:\path
and verify the output.
You can also verify java home path by writing a simple Test class like following:
public class Test {
public static void main(String[]s){
System.out.println(System.getProperty("java.home"));
}
}
There are multitudes of links to be fond on Google regarding how to solve this in Windows. These environment variables typically do not get setup by default when installing java.
Here are some 10 second finds with with answers:
How to set java_home on Windows 7?
Setting the JAVA_HOME Variable in Windows
Installing Java on Windows 7 and setting-up the JAVA_HOME
Check you PATH variable in Environment Variables. It must be set to jreInstallation/bin. Windows does not pick up java command from JAVA PATH, it picks java command from PATH variable.
Also note that once you install JDK, path is not set by installation to jdkInstallation/bin, you need to set it up explicitly.So unless you set the path to jdkInstallation/bin, javac wont be recognized.
Check your path variable in windows environmental variables. At least Java path should be there .
It may looks like this.
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jdk1.7.0\bin
You should set path and classpath variables.
Here's the link you can follow for step by step instructions.
[http://abodeqa.wordpress.com/2012/08/11/how-to-set-path/][1]
With Java, Groovy, Git, Heroku, Maven, and many other projects, what I always do is this:
1. Unzip the software package into a directory, for example:
C:\AeroFS\Java\jdk1.7.0_25
C:\AeroFS\Groovy\groovy-2.0.5
2. Create a HOME variable, such as JAVA_HOME or GROOVY_HOME that points to the
above locations.
3. Put these in your default system path by editing your PATH variable and
adding %JAVA_HOME%\bin and %GROOVY_HOME%\bin to the end of your PATH. In
the case of JAVA_HOME only, you might want to put it at the beginning of
the PATH to override the java.exe that rests in the WINDOWS directory
location.

I'm trying to set my JAVA_HOME path to use my javac.exe?

I'm on Windows 7 and I'm trying to set my JAVA_HOME path to use PhoneGap on android, when i create a project using the command line "cmd" it tells me that it can't find javac.exe? although i'm sure that I've set the variable right
here's my stuff:
Variable name: JAVA_HOME
Variable value: C:\Progra~1\Java\jdk1.7.0_17\bin
(I've also tried to use: C:\Progra~1\Java\jdk1.7.0_17\bin\javac.exe)
My javac.exe location on my laptop C:\Program Files\Java\jdk1.7.0_17\bin\javac.exe
and it still tells me that it can't locate the javac.exe
What I type to create the project and i meet this problem is this:
C:\Users\user>cd C:\Users\user\Desktop\phonegap-2.8.1\lib\android\bin
C:\Users\user\Desktop\phonegap-2.8.1\lib\android\bin>create.bat
Cannot locate javac.exe using the PATH environment variable.
Retry after adding directory containing javac.exe to the PATH variable.
Remember to open a new command window after updating the PATH variable.
Visit http://java.oracle.com if you need to install Java (JDK).
Also, i've tries restarting the windows and closing the command prompt and redownloading the JDK.
Thank You.
cmd is using the values from the PATH variable to locate javac :
set "PATH=%PATH%;C:\Program Files\Java\jdk1.7.0_17\bin"
For other softwares (Tomcat, Maven, etc.) JAVA_HOME must indicate the root of your JDK :
set "JAVA_HOME=C:\Program Files\Java\jdk1.7.0_17\"
No need to restart Windows. When using set the changes are taken immediately.
If you choose to modify those variables in the Control Panel, you have to close and relaunch cmd for the changes to take effect.
You have to add java
C:\Program Files\Java\jdk1.7.0_17\bin
Note that your path may be different.
to your environment variables and restart your console.
You can find how to set your variables here:
http://www.itechtalk.com/thread3595.html
Set the JAVA_HOME Variable
Right-click the My Computer icon on your desktop and select Properties.
Click the Advanced system settings. 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(C:\Program Files\Java\jdk1.7.0_17).
Click OK.
Click Apply Changes.
You might need to restart windows.
Set the JAVA_HOME environmental variable to
C:\Program Files\Java\jdk1.7.0_17
Press
Win + Break > Advanced System Settings > Environment Variables > System Variables
Modify/set JAVA_HOME to the above. (No need to restart)
I already had this error when I tried to create a new phonegap project for android but unfortunately I don't remember how exactly I have fixed this.
I don't know if you have followed the phonegap documentation so here is the link : new project, especially the part 3B (be careful about ; in your PATH).
If you don't know what to do now, maybe you should do it again step by step.
May be a little old, but since this is the first goolge result, I might as well add a little something.
You need to create the JAVA_HOME variable AND edit the PATH variable, adding ;%JAVA_HOME%\bin (with a ;) so cmd and some other apps can actually use javac and the rest of the tools

Windows/NetBeans platform - Getting JAVA_HOME environment variable into conf file

I'm trying to use the JAVA_HOME windows environment variable as the jdkhome directory in a netbeans platform application. The variable is definitely set (it was originally a user variable, but I added an environment variable as well because I thought that might be the issue). My config file currently contains the line
jdkhome="${JAVA_HOME}"
I tried
jdkhome=${JAVA_HOME}
as well. Neither of these work - it says there is no valid java install. It does work if I manually write out the directory that JAVA_HOME points to.
I've tried asking on the official netbeans forum, but there hasn't been any response.
Any advice?
Try %JAVA_HOME% and see if that works.

Change where Java looks for javac.exe

I am trying to upload my GAE app using the console in windows. I am getting the error:
cannot find javac executable based on java.home tried, "C:\Program Files\Java\jre6\bin\javac.exe" and "C:\Program Files\Java\bi
n\javac.exe"
Unable to upload app: cannot find javac executable based on java.home, tried "C:
\Program Files\Java\jre6\bin\javac.exe" and "C:\Program Files\Java\bin\javac.exe
javac.exe is located in C:\Program Files\Java\jdk1.6.0_18\bin how do I tell java thats where it is
You must set the JAVA_HOME environment variable to refer to the top-level folder where java is installed. Right-click "My Computer", Properties, Advanced, Environment Variables. If there's an existing JAVA_HOME variable, then correct it so that its value is
C:\Program Files\Java\jdk1.6.0_18
If there is no existing variable, then create one by using the "New" button. It's up to you whether to do it for the current user or for the system.
Do you have two java versions installed?
From the information the sun jre and the Open jdk? The jre has no javac.exe and therefore cant find it.
Try to start your jar with C:\Program Files\Java\jdk1.6.0_18\bin\java.exe instead of only java, if that doesn't help add the -Djava.home="C:\Program Files\Java\jdk1.6.0_18" option to the call.
The error message makes it clear that the lookup is based on java.home, have you tried adjusting that?
This output looks like it is coming from some sort of script which may have it's own definition of java.home which you need to change.
The easiest solution for this problem which I found is to use the JAVA_HOME variable in the script file.
This is the content of my bin\appcfg.cmd:
#"%JAVA_HOME%"\bin\java -cp "%~dp0\..\lib\appengine-tools-api.jar" com.google.appengine.tools.admin.AppCfg %*
Note: you should also check if JAVA_HOME points to an existing JDK
The other way you can do set classpath variable using set CLASSPATH=C:\Program Files\Java\jre6\bin\javac.exe\jdk1.6.0_18 in command prompt, but it works for single session.Everytime you need to set the variable.
Set your JAVA_HOME environment variable to C:\Program Files\Java\jdk1.6.0_18. Note that this variable points to the JDK location, not (unlike the PATH environment variable) to the path where the executables reside.

Categories