• 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

Newbie Classpath question

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your insight.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic