Forums Register Login

Newbie Classpath question

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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).
+Pie Number of slices to send: Send
Thanks for your insight.
+Pie Number of slices to send: Send
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 once met a man from Nantucket. He had a tiny ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 622 times.
Similar Threads
Help me please! Can't find class message.
Problem in javac and java command
Ready to drink a jar
JDBC Drive Issue
Why does my java program only run with -debug in my parameters
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 03:03:52.