Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

path variable

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C:\Program Files\Java\jre1.5.0_06\bin

this is the path for my java bin files.

Now when I try to compile my java class at command prompt as "javac SomeClass.java" , I get an error message "'javac' is not recognized as an internal or external command,
operable program or batch file."

Does it mean that path I have set is for compiled program ? i e if I want to run java SomeClass, then this will work ? So which path do I need to set to compile the program ?
 
Marshal
Posts: 7251
1392
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy Nirali,

The problem is that command "javac" is not indentified. Do a search for the file "javac.exe" and discover the directory (folder) where that file is placed. And then, you have to set the path to that directory.

Devaka.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have two options:
1) In the command prompt write set path=C:\Program Files\Java\jre1.5.0_06\bin and then you can compile the program by simply typing javac anyProgram.java
2)Write click my computer, go to environment variable and add the the path C:\Program Files\Java\jre1.5.0_06\bin to the Path variable

If you chose the 2nd option, you will need not to set the path every time you open the command prompt.
 
nirali shah
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did following.
I kept my source code directly under C:\
At the cmd prompt, I executed following exe file "C:\Program Files\Java\jdk1.6.0_11\bin>javac c:\AnyClass.java" So the source code did compile and class file is created under c directory.
Now when I do "C:\Program Files\Java\jdk1.6.0_11\bin>java c:\AnyClass"., I get following error

------------------------------------------------------------------------------------

C:\Program Files\Java\jdk1.6.0_11\bin>java c:\AnyClass
Exception in thread "main" java.lang.NoClassDefFoundError: c:\AnyClass
Caused by: java.lang.ClassNotFoundException: c:\AnyClass
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: c:\AnyClass. Program will exit.
------------------------------------------------------------------------------------------

I tried to keep classfile in different folder and try to execute from there, but same error.

Whats this due to ? How to correct this ?
 
Marshal
Posts: 79637
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While you are at it, why not upgarde to Java6?

It is actually set path=C:\Program Files\Java\jre1.5.0_06\bin;%PATH% or something like that. Otherwise other programs in the PATH will vanish. And if you set up the PATH like that, you will only have that PATH for the lifetime of that command prompt window. Fuller instructions can be found by looking up your problem in this "common problems" page.
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



C:\Program Files\Java\jdk1.6.0_11\bin>java c:\AnyClass
Exception in thread "main" java.lang.NoClassDefFoundError: c:\AnyClass



You cannot run java command like that , java excepts the file name and " not the absolute pathname of the file " , the file can be in the CLASSPATH directory and

Add C:/anydirectory to your CLASSPATH , place your class file inside C:/anydirectory ( if its packagee , place entire package) and run "java anyClass" from anywhere ( any path i mean : ))
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nirali shah wrote:C:\Program Files\Java\jre1.5.0_06\bin





you are trying to execute javac which needs jdk
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is all getting confusing....
First things first,
1. You need to have jdk installed to compile java files . Default Install directory is : "C:\Program Files\Java\jdkXXXXXX" where XXXXXX is the installed jdk version.
2. Set value of the PATH variable as follows:
To set the PATH permanently, add the full path of the jdk1.6.0_<version>\bin directory to the PATH variable. Typically this full path looks something like C:\Program Files\Java\jdk1.6.0_<version>\bin. Set the PATH as follows on Microsoft Windows:

Click Start > Control Panel > System on Windows
Click Advanced > Environment Variables.
Add the location of bin folder of JDK installation for PATH in User Variables and System Variables. A typical value for PATH is:
C:\Program Files\Java\jdk1.6.0_<version>\bin
PATH environment variable is a series of directories separated by semi-colons (;) and is not case sensitive. Microsoft Windows looks for programs in the PATH directories in order, from left to right.
You should only have one bin directory for a JDK in the path at a time. Those following the first instance are ignored. If one is already present, update it to jdk1.6.0_<version>\bin.
If you are not sure where to add the path, add it to the right end of the PATH in the User Variables.
The new path takes effect in each new command window you open after setting the PATH variable.

3. To compile any java file, cd to the directory where it is located and type the command:
Directory>javac <yourFileName>.java

4. To execute a class file, cd to the containing directory and type:
java <yourClassName>


Hope this helps.....
 
Campbell Ritchie
Marshal
Posts: 79637
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That should help. I would add:

It is a good idea to create a "java" folder to keep all your .java and .class files.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must download java jdk1.6.0 or something like that. Set environment variable modify path to add jdk1.6.0 bin path.
in command prompt type this : path c:\program files\java\jdk1.6.0\bin or you can create batch file also.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that he has his path set to a JRE bin folder, not a JDK. JRE install does not include javac utitily, only java and some others. You need JDK to get the javac utility.


Simple fix: download the JDK, NOT the JRE. Then go find the bin folder for that as you did with the JRE, append it to the PATH variable, then you'll be fine. Delete yor JRE reference as well from the path variable. Nothing will happen if you don't. Windows will simply look in that path first for javac/java commands but won't find the javac command and thenw ill go to the next entry in the PATH variable (the right one with the JDK path).

You can simply type javac at the ommand prompt to test it. Remember, if you leave a command prompt/shell open and do these changes, they won't take affect until you cloe and open a new shell.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lots people get confused with this.

Windows OS Shipped with default JRE not JDK
If your system does not have JRE, Any site which has applet can prompt you to download JRE automatically to your system. And you might have JRE in that scenario.

JRE: Runtime environment.
JDK: Development kit

So you can not develop java application without a JDK, what it names speaks a lot.

So in JRE you will not find java compiler which is javac.

Do not confuse yourself. Java is an open standard as per the rule every OS must have JRE.

So do not consider using JRE you can develop java program. You can run though, but to develop you must download JDK from sun site
http://java.sun.com/javase/downloads/index.jsp

And after download and install point your path till bin directory.

Simply for Windows
Prompt:> set path=%path%;JDK_INSTALLED DIR_HOME_PATH/bin;
e.g, set path=%path%;C:\Program Files\Java\jdk1.6.0_06\bin;

Simply for Linux
Prompt:> export PATH=$PATH:/JDK_INSTALLED DIR_HOME_PATH/bin
e.g, export PATH=$PATH:/usr/java/jdk1.6.0_06/bin

reply
    Bookmark Topic Watch Topic
  • New Topic