• Post Reply Bookmark Topic Watch Topic
  • New Topic

ClassPath not Set  RSS feed

 
Andrew McHorney
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • 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.
 
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
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!