Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie Classpath question

 
Scott Matthews
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been programming in java for about 6 months writing small programs to learn different areas of Java. I always compile and run the programs I create from the command line (dos prompt - Ex: javac TestProgram.java & java TestProgram). My programs after debugging have always ran just fine, but I cannot tell anywhere on my Win98 computer where I have a "classpath" set.
Today, I ran into a situation where I needed to refer to a specific jar file. I read information on the "classpath" and I explicitly put it in the command line as "java -classpath ..\lib\test.jar TestProgram" and it found the jar file and ran fine.
Question: I am confused on the use of the "classpath". Should I always have one and if so, why has this NOT bitten me in the foot sooner?
Additional information:
- JDK version 1.3.0
- I have a path set in my autoexec.bat that refers to my
JDK "bin" folder. I cannot see any other "set" type commands
to "set" the classpath.
- I never have put the "-classpath" in until today.
Thanks for your time.
 
John M. Gabriele
Ranch Hand
Posts: 232
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott,
The days of having to set an actual CLASSPATH variable are gone. As you've already done, the only way you're supposed to deal with the class path nowadays is by specifying it on the command line (er.. dos prompt; my condolences ) after -classpath or -cp.
You haven't needed it in your own programs because you've never put a package statement at the top of any of your source code files.
You haven't needed it running other java programs until now because they've all been self-contained; that is, they've always contained all the classes they needed (besides the core java classes which they always know where to find anyhow).
 
Scott Matthews
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your insight.
 
akadiyala
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On windows, you go to Control Panel/System/Advanced tab/Environment variables (this is not a dir path!!!). here you can edit your classpath and other environmental variables
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic