Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting up classpath. javac is not recognized

Tags:

java

javac

I am trying to run my java program from command line.

I read an article about setting up classpath, but I get an error of javac is not recognized as internal or external command. What should I do? (I dont want to set a permanent CLASSPATH) This is what I have done in my command line

D:\user> set path=%path%;C:\Program Files\Java\1.7.0_07\bin

D:\user> cd testing

D:\user\testing> javac firstProgram.java
'javac' is not recognized as an internal or external command,
operable program or batch file.

Thank you

like image 255
kaboom Avatar asked Jan 15 '23 09:01

kaboom


2 Answers

Assuming that the PATH is correct1, the most likely cause is that you have a JRE installation ... and a JRE doesn't include a java compiler. You need a JDK installation if you want to compile from the command line.

(You can confirm this by looking in the C:\Program Files\Java\1.7.0_07\bin directory to see if it contains a javac.exe file. A JRE won't ...)

Where can I find the Java compiler to download..

You need to download one of the JDK installers; see http://www.oracle.com/technetwork/java/javase/downloads/index.html


1 - I don't think quotes are required in a PATH variable on Windows. At least that's what various examples that Google found for me seem to imply. But I've never really understood the logic behind quoting in Windows ...

like image 155
Stephen C Avatar answered Jan 22 '23 14:01

Stephen C


Its an issue related to Program Files.

First make sure that your JDK Folder is installed in Program Files or Program Files(x86) or any other folder.

Then you should use the path of bin folder in " ". Because command prompt does break the string at space. When you will write it in " " then it will take is as a whole String.

You try these commands

set path=%path%;"C:\Program Files\Java\1.7.0_07\bin"

or

set path=%path%;"C:\Program Files(x86)\Java\1.7.0_07\bin"

It might help you to get out of this.

like image 36
MouseCrasher Avatar answered Jan 22 '23 15:01

MouseCrasher