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

ClassPath not Set

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I just installed the latest JDK for Java. I did a check on my windows environment variables and I noticed that the class path is not the path that I installed Java into. It is the original path that was setup when the operating system was installed. Why would this happen? I thought perhaps that the install failed but when I went to install it again I was told that the version of the software was alread installed.

Any comments on why this would happen would be appreciated.

Thanks,
Andrew
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought Windows didn't set a default classpath, only a path. There are some applications which set themselves a classpath, in which case you need to add .; for "current directory" to it. Your classpath is where you put your compiled Java™ work, and the path is where the computer looks for the executable files (eg "java"). The classpath does not usually point to the Java™ installation directory, but the path ought to.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrew McHorney wrote:I just installed the latest JDK for Java. I did a check on my windows environment variables and I noticed that the class path is not the path that I installed Java into.


The classpath is what Java uses to find *.class files, but the standard Java library does not need to be in the classpath - Java always includes that automatically. Your classpath should not include the directory where you installed the JDK - that's not normally a directory where you would save your *.class files. As Campbell says, when you install the JDK, it doesn't set a CLASSPATH environment variable, and it's recommended not to set it at all. If CLASSPATH is not set, Java will by default look in the current directory for class files.

If you need to set a classpath for running your program, set it on the command line by using the -cp or -classpath option instead of setting a CLASSPATH environment variable.

The reason why it's better to not use the CLASSPATH environment variable is because it affects all Java programs that you run on your system, which is usually not what you'd want.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic