nusCS2113-AY1819S1 / forum

5 stars 0 forks source link

Cannot open Jar file #87

Closed px1099 closed 6 years ago

px1099 commented 6 years ago

When I try to open a Jar file, these errors pop up: Error: could not find java.dll Error: could not find Java SE Runtime Environment

Psyf commented 6 years ago

Did you check whether JAVA_HOME is set? Instructions: https://www.thewindowsclub.com/set-java_home-in-windows-10

px1099 commented 6 years ago

I already set it to D:\Java\jdk-9.0.4

Psyf commented 6 years ago

If the tests in the previous article pass then idk. A friend was facing issues just because Jdk wasn't in Program Files for some reason (weird I know). Maybe look into that?

0WN463 commented 6 years ago

Try java --version and javac --version and see if they are correct

px1099 commented 6 years ago

java --version Error: could not find java.dll Error: could not find Java SE Runtime Environment

javac --version javac 9.0.4

0WN463 commented 6 years ago

That would mean that the jdk is set up properly, but the jre(used to running java applications) is not

Psyf commented 6 years ago

A side question: given JRE is a subset of JDK, shouldn't the JDK be able to run the .jar file?

px1099 commented 6 years ago

Given that gradlew and intelliJ are still working perfectly fine, this is very unusual

So this is the full context: A few day ago, I opened java control panel and accidentally uninstalled jre 9 and jre 10 I reinstalled jre 9 and 10 and set up the Path, and I managed to continue developing the project as usual But now these errors appear when I try to open the jar file

Can I ask how to fix this?

Psyf commented 6 years ago

Not too strange. IntelliJ initializes with its own project variables, which are correctly set for you.

Make sure your system variables:

  1. Have a variable JAVA_HOME pointing to jdk
  2. System Variables -> Path has a path to jre\bin and another path to %JAVA_HOME%\bin
QzSG commented 6 years ago

To check if java is set correctly, running where java after setting up the paths saif mentioned should return your JDKPath\bin\java.exe

px1099 commented 6 years ago

After trying some solutions for a while, I decided that this is too problematic and "Hard reset": uninstall everything, and then only install jdk-9.0.4 After installing, I set up the environment variables based on the guide in this website: https://stackoverflow.com/questions/1672281/environment-variables-for-java-installation It is working fine now.