• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Classpath not working

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have created classpath for working with java as follows:

Variable: CLASSPATH
Value: .;C:\Program Files\Java\jdk1.6.0_13\bin;


is this correct? I believe once we set classpath we'll be able to work from anywhere in the computer.

I'm using Win 7.
 
Ranch Hand
Posts: 466
1
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John,

Classpath should point to your JDK lib directory. It should be like C:\Program Files\Java\jdk1.6.0_13\lib .

Regards
Vinod
 
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

Vinod Tiwari wrote:
Classpath should point to your JDK lib directory. It should be like C:\Program Files\Java\jdk1.6.0_13\lib .



Wrong!. java.exe is lies under bin folder . Jhon is right.

@ john .;C:\Program Files\Java\jdk1.6.0_13\bin;

i guess you are using environment variable. what is the need of .; --> which is at the starting and ; at the end ?
 
Seetharaman Venkatasamy
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

John Eipe wrote: I believe once we set classpath we'll be able to work from anywhere in the computer.



Can you elaborate ?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're both wrong.

The *path* should be \bin, that's what determines what executables are available to be run without typing in their full path.

The *classpath* determines what classes and/or jar files are available without specifying them manually--and setting it to "lib" won't have any effect: jar files must be specified individually, while class hierarchy directories just need the directory name.

Setting a classpath can often cause more trouble than it's worth.
 
Seetharaman Venkatasamy
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
Thank you David
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks....

Value: .;C:\Program Files\Java\jdk1.6.0_13\bin;



I removed .; and ; from the above and still it doesn't work. When I run javac from command prompt i still get the not recognized message.

I believe once we set classpath we'll be able to work from anywhere in the computer.



I mean once it's set. we could run programs from any drive. Also isn't it a good idea to set classpaths?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you putting quotes around the path? There are spaces in the name, so they're required.

Setting a classpath can cause more problems than it solves. Most people recommend not to. *I* set classpaths, because I run a lot of stuff from the command line, but I set it per-app, through shell scripts, depending on what I happen to be working on. In general, I don't recommend it. It's easy enough to set a different environment variable and use it in java and javac command lines.
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks David.

I tried with quotes - nothing happens . anyways as you suggested I'll continue without setting classpaths.

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Nothing" happens? I find that unlikely.

Post *exactly* what you're typing to set the path, what you type to run javac, and the output. According to your first post, you're setting the classpath to what should be the path.
 
Seetharaman Venkatasamy
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

David Newton wrote:Are you putting quotes around the path? There are spaces in the name, so they're required.



i think,if you are setting through environmental variable,then it is not required. it is required incase of running a java class through command promt .
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is not correct; spaces are significant.
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,

Below are the details:

JDK installation path: C:\Program Files\Java\jdk1.6.0_13\bin

source path: E:\JSpace\firstprograms\src
compiled classes path: E:\JSpace\firstprograms\classes

Below is what i tried on dos prompt.


E:\JSpace\firstprograms\src>javac -d E:\JSpace\firstprograms\classes -classpath "C:\Program Files\Ja
va\jdk1.6.0_13\bin" pro1.java
'javac' is not recognized as an internal or external command,
operable program or batch file.

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because you're *still* not setting the path to include the directory that has the Java compiler on it.

Do you understand there is a difference between a path and a classpath?

Dave wrote:The *path* should be \bin, that's what determines what executables are available to be run without typing in their full path.

The *classpath* determines what classes and/or jar files are available without specifying them manually--and setting it to "lib" won't have any effect: jar files must be specified individually, while class hierarchy directories just need the directory name.


They are not the same thing. Here you've once again used the path as the classpath. So to reiterate: the path lists the directories that will be searched for executables. A classpath lists the the Java class directories and/or JAR files that will be used to load Java classes

The path needs to include the directory containing the Java compiler executable.
 
Ranch Hand
Posts: 45
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John,

Set Path variable to C:\Program Files\Java\jdk1.6.0_13\bin directory and JAVA_HOME variable to C:\Program Files\Java\jdk1.6.0_13 directory

Setting Classpath variable can be ignored for this issue.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree with David, need to set the path for the o/s to find the executable such as javac. If want to do this once and forget about it until you upgrade jdk's set path via (for XP)

Control Panel => System => Advanced => Environment Variables => System variables => select variable Path and Edit

add C:\Program Files\Java\jdk1.6.0_13\bin at end of existing string. I need to copy to notepad and edit and paste back because edit window is so small.

 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's working now! What exactly is JAVA_HOME for?

David,

Please correct me if i'm wrong.
Path variable is for locating exe files.
Classpath variable is for locating class files, jar, etc.
There is no way we could compile java programs without setting path variable.

Thanks.
 
Marshal
Posts: 79923
395
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try a few variations. Try putting the quotes round the entire PATH. Try missing out the quotes again. Try the following at the command line:

C:\Program Files\Java\jdk1.6.0_13\bin\javac -version
and
"C:\Program Files\Java\jdk1.6.0_13\bin\javac -version"

and see whether you get the same error. Confirm that you are in fact using the 13th upgrade in its default location.
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic