Home > Back-end >  java -cp/javac doesn't work in cmd prompt
java -cp/javac doesn't work in cmd prompt

Time:02-25

I am trying to run mo program by cmd :

  • first i try to compile my Main.java by "javac Main.java", after that i have no msg in cmd
  • second i run "java -cp Main"(Main.class with byte code), after that i have no output in cmd I tryed reinstall my JDK, but it doesn't help. also when i run "java -version" in cmd i have no output. and no msg.I has set my JAVA_HOME path into JDK dir and set him into my PATH "%JAVA_HOME\bin". what i cant do wrong? Pls help

enter image description here enter image description here enter image description here

CodePudding user response:

Your path environment variable for java is not set correctly. You could try to run the command where java and most likely it will return a path that is not correct (or nothing). Find the correct path where your JDK is installed and run this command to add it to the path vars in cmd:

set PATH=%PATH%;C:\your\path\here\

An example for my system and path would be:

set PATH=%PATH%;C:\Program Files\Java\jdk-11\bin

After setting this path variable, close and reopen your cmd window and try running java -version again. If it still doesn't show anything then you have to manually change your path variables and remove the old path.

CodePudding user response:

Make sure that you have correctly set the path to the directory in which you have your java installed. For instance mine is settled in D:\Program files\java\jdk-11.0.2

Subsequently I set JAVA_HOME as JAVA_HOME

Then you open path variable and new entry as following: path variable

Then save all changes. Close all running cmd, start it again and then retry java -version

  • Related