aspose file tools*
The moose likes Beginning Java and the fly likes Newbie Classpath question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Newbie Classpath question" Watch "Newbie Classpath question" New topic
Author

Newbie Classpath question

Scott Matthews
Ranch Hand

Joined: Jun 28, 2001
Posts: 36
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

Joined: Feb 18, 2001
Posts: 232
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

Joined: Jun 28, 2001
Posts: 36
Thanks for your insight.
akadiyala
Greenhorn

Joined: Feb 05, 2001
Posts: 3
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
 
subject: Newbie Classpath question
 
Similar Threads
Help me please! Can't find class message.
JDBC Drive Issue
Problem in javac and java command
Why does my java program only run with -debug in my parameters
Ready to drink a jar