java -cp/javac doesn't work in cmd prompt - java

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

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.

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
Then you open path variable and new entry as following:
Then save all changes. Close all running cmd, start it again and then retry java -version

Related

Run jps on command promt

I installed Hadoop and tried to run it. The terminal shows that everything has been started but when I run jps command it shows :
'jps' is not recognized as an internal or external command,
operable program or batch file.
I set JAVA_HOME= C:\Progra~1\Java\jre1.8.0_261 and path = C:\Progra~1\Java\jre1.8.0_261\bin and C:\Program~1\Java\jre1.8.0_261\legal\jdk in enviroment, but when I type jps in command prompt it shows : Not recognized as an internal or external command.
I don't know what can I do, Help me, please.
It looks like the jps executable is no present in the bin directory that you've specified in system environment variable. It should be inside C:\Program Files\Java\jdk1.8.0_261\bin if you have jdk1.8.0_26 installed in your system in the location C:\Program Files. Try specifying the JAVA_HOME like this:
Go to Control Panel -> System -> Advanced System Settings -> Environment Variables.
Add a new path variable called JAVA_HOME:
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_261
Select Path from System Variables and click Edit.
Remove the existing Java path and add the new path as %JAVA_HOME%\bin
Now, open command window, type jps and hit ENTER.
Note: You can download JDK from here

The system cannot find the path specified: Error while starting zookeeper(Apache Kafka)

I am getting the below error while starting Zookeeper server in the command prompt:
The system cannot find the path specified.
I am using Windows 8 OS, Kafka 2.12 and Java 8 JDK.
I have checked on the below:
Set JAVA_HOME to JDK bin folder.
Set the PATH environment variable correctly using JAVA_HOME as the relevant path.
Set the CLASSPATH environment variable correctly using JAVA_HOME as the relevant path.
Used shortened path in windows to avoid using spaces:
Ex: C:\Progra~1 instead of C:\Program Files
Checked on the below commands in the command prompt:
echo %JAVA_HOME%
echo %PATH%
echo %CLASSPATH%
where java
java -version
java -d64 -version
javac -version
All of them gave me the specified path. However it didn't resolved my issue.
I think JAVA_HOME should keep till JDK path not JDK\bin.
There is this file kafka-run-class.bat which gets referenced in most of the kafka scripts. It sets the JAVA parameter depending on the JAVA_HOME variable mentioned below:
set JAVA="%JAVA_HOME%/bin/java"
We need to modify this since JAVA_HOME already contains path until 'bin'. So now Kafka tries to append an extra bin directory to the path. We need to alter this as mentioned below:
set JAVA="%JAVA_HOME%/java"
Now on starting the zookeeper again in a fresh command prompt the error is gone and the zookeeper starts fine.
I was also facing the same issue:
My java home set was
C:\Program Files\Java\jdk1.8.0_144\bin
Then i did the following change:
1)changed the jdk location to C:\Java\jdk1.8.0_144\bin as earlier location was containing spaces between Program and Files.
2)Also i need to change the kafka-run-class.bat file from
IF ["%JAVA_HOME%"] EQU [""] (
set JAVA=java
) ELSE (
set JAVA="%JAVA_HOME%/bin/java"
)
to
IF ["%JAVA_HOME%"] EQU [""] (
set JAVA=java
) ELSE (
set JAVA="%JAVA_HOME%/java"
)
.
As my java home already contains /bin suffix.So either remove the bin suffix from your java home or modify the kafka-run-class.
But still i was getting same error when running from the command prompt.Then i closed the cmd and again opened the new command prompt and run the following command and it run successfully.
.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
Note:If you modify the system variable then you need to restart the system.

Java and javac not working in cmd. Both java and javac "is not recognized as an internal.."

I am having som trouble with java, i have tried to fix my Path, but i am new to programming and don`t know what to do.
I have java installed at : C:\Program Files\Java\jdk1.8.0_92\bin
and at : C:\Program Files (x86)\Java\jdk1.8.0_91\bin
Here are some screenshots from my system variables: This pops up when i click on the system variable "Path", see the other picture.
System variables
When I am in cmd, and writing java -version or javac -version, I get this message:
"java/javac is not recognized as an internal or external command, operable program or batch file".
Have tried to restart cmd every time i have changed the path.
Try Setting separate variables for JDK & JRE
Also give a backslash "\" after bin in the case of both JDK & JRE
Hope this works
First go to this path to make sure that it is right.
second try to restart your cmd and try again.

Unable to set Java Path in system variables (Windows 10)

I've tried adding JAVA_HOME with the directory - C:\Program Files\Java\jdk1.8.0_121 to my system variables, and then adding %JAVA_HOME%/bin to Path variable and this didn't work and I receive
'java' is not recognized as an internal or external command, operable
program or batch file.
So I've tried adding C:\Program Files\Java\jdk1.8.0_121; directly to the path variable but I still get the above error. Does anyone have any suggestions please?
Thanks
PS - The image shows me in the command prompt at C:\Program Files\Java\jdk1.8.0_121 trying 'java -version' - I just moved up one dir to test the variable, entering 'java -version' in the bin directory returns the correct info, as you would expect.
Did you try closing that command prompt and reopening it?
In the command line, run the following:
set PATH=%PATH%:C:\Program Files\Java\jdk1.8.0_121\bin
Without exiting the shell, run your java commands
E.g.
java -version
This will surely work.

Javac Command Not Working

My javac command is not working.
"javac is not recognized as an internal or external command, operable program or batch file."
-java version WORKS
I've tried setting classpath successfully in command prompt. SET CLASSPATH "C:\Program Files\Java\jdk1.7.0_09\bin";
Ive adding it in environment variables. ;C:\Program Files\Java\jdk1.7.0_09\bin ;C:\Program Files\Java\jre7\bin
Ive checked the bin folder java.exe is there aswell as javac.exe.
^ Tried all of these still doesn't work. I've also restarted command prompt still does not not work.
Why is not working?
You're using the correct path apparently, but you should assign it to the PATH variable, not to the CLASSPATH variable.
You're trying to set the access path to the executable files, not to the class files.
Just do this
In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK,
e.g. C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in your Path environment variable.
Just set JAVA_HOME to
C:\Program Files\Java\jdk1.7.0_09
After adding the path to the jre7\bin-Folder to the PATH-Variable, you need to restart your Computer in most cases.
Did you tried to create a JAVA_HOME variable? The value should be the path of the java without the bin.
Also, try to open Eclipse.
If nothing helps, the last thing that you can do is install netbeans, it will configurate everything.

Categories

Resources