问题
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!
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/25336179/libgdx-not-using-correct-java-home-path