Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libgdx not using correct JAVA_HOME path

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

enter image description here

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

enter image description here

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

enter image description here

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!

like image 464
user1706538 Avatar asked Feb 13 '23 05:02

user1706538


2 Answers

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.

like image 149
Rudey Avatar answered Feb 14 '23 19:02

Rudey


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.

like image 44
shaneo Avatar answered Feb 14 '23 20:02

shaneo