• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot run java program in command prompt  RSS feed

 
Nivesh Chandola
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I am new to new to Java and after making the program in the text editor I saved it as .java type. After running the program in command prompt I got the following error:

'javac' is not recognized as an internal or external command, operable program or batch file.
Captured_error_in_java.JPG
[Thumbnail for Captured_error_in_java.JPG]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you installed a JDK? Is the directory containing javac in your system path?

Also, can you run "java -version"? If so, you might have installed a jre instead of a jdk?
 
Wayan Saryada
Ranch Hand
Posts: 119
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you've install a JDK in your machine you'll need to update your Path environment variable so that you can call the javac and java command from anywhere in you command prompt. If you are on Windows then your JDK usually installed under Program Files\Java\some-version-of-jdk.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the JDK installation instructions: Updating the PATH Environment Variable
 
Nivesh Chandola
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,

I have downloaded jdk and have updated the Path environment variable but still I am getting the same message.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what is your PATH set to? and where is your JDK install?

In other words...the PATH simply holds a list of directories the OS uses to try to find programs. one of the directories in your PATH should be the location of "javac.exe".

I would say find your javac.exe, and then put that directory in your PATH.
 
Nivesh Chandola
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My jdk is installed in Program files(x86) and Path is set to
C:\Program Files (x86)\Java\jdk1.7.0_25\bin
 
Wayan Saryada
Ranch Hand
Posts: 119
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always check to see if the Path is exists and point to the correct path by typing echo %PATH% in your command prompt.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nivesh Chandola wrote:My jdk is installed in Program files(x86) and Path is set to
C:\Program Files (x86)\Java\jdk1.7.0_25\bin

if that is the ONLY thing in your path, you are probably going to have other issues, but that's another story.

did you cd into that directory? is the program "javac.exe" there? did you close any open cmd window and open new ones after you updates and saved your new PATH?
 
Nivesh Chandola
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes "javac.exe" is there in the bin and yes I made the new PATH in Advanced System Setting under "environment variables" but I named it as CLASSPATH because in PATH I have given the address of my MATLAB program to run MATLAB files.

No I didn't close any open cmd window.
 
Abhishk Singh
Ranch Hand
Posts: 55
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Even if the PATH is pointing to Matlab directry, you can append it by placing a semicolon (;).
The semicolon separates different directories.
Try appending the jdk path to PATH variable under environment variables. The system may need a restart for changes to take effect.
 
Josh Rowe
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do what Abhissk said. The semicolon operator separates different paths in your PATH variable. You cannot make another variable as Windows will not recognize it as "Path" unless you want to dive deep in your system. Believe me, I tried and thought I was doing it right, when in fact, I should have just added more to the original path variable.
 
Nivesh Chandola
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone, it was my mistake I created the CLASSPATH which of no use.
It is working now.
 
milan chovatiya
Greenhorn
Posts: 24
Java Oracle Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cmd commands for setting this variables


set path=%path%;full location of your jdk bin folder
set classpath=%classpath%;location of your project folder
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!