CLASSPATH, -cp and -classpath misunderstanding?

F

Flip

Hello, I'm working on a Head First EJB book (it's great), but I have a
question about CLASSPATH, the -cp and the -classpath.

I understand javac uses the -classpath parameter and java uses the -cp, but
why are they different parameter names? Why aren't they the same? Don't
the reference the samething? How do each of them work with the environment
CLASSPATH variable? I am running a javac command and it appears to be
ignoring my CLASSPATH setting, I have to explicitly put the jar I want on
the javac command line to not get any errors.

I'm using Windows XP if that matters. Thanks for any help.
 
A

Andrew Thompson

Flip said:
..I have a
question about CLASSPATH, the -cp and the -classpath.

I understand javac uses the -classpath parameter and java uses the
-cp, but why are they different parameter names?

java -classpath ...
also works, Sun just allow the -cp short version
for convenience, but since it is inconsistently
supported, I always use -classpath
..Why aren't they the
same?

(shrugs) 'Go figure' is the best explanation
I have come up with.
..Don't the reference the samething? How do each of them work
with the environment CLASSPATH variable? I am running a javac
command and it appears to be ignoring my CLASSPATH setting, I have to
explicitly put the jar I want on the javac command line to not get
any errors.

It is better to do that, so that different projects do
not clash, but unfortunately Sun recently removed
the document (part of the 1.2 API docs) that
mentions that. Now they seem to be drifitng back
to setting the CLASSPATH variable.

I think this is a sub-optimal solution and stick
with -classpath.
I'm using Windows XP if that matters.

Given you are using such a fragile OS,
I would strongly recommend you use
the -classpath option. ;-)
 
F

Flip

Thanks for the quick response.
java -classpath ...
also works, Sun just allow the -cp short version
Oh, I see, I never thought of trying it like that, duh. Thanks.
(shrugs) 'Go figure' is the best explanation
I laughed when I read that. That's kind of what I thought too, but I like
your explanation. :>
Given you are using such a fragile OS,
I would strongly recommend you use
the -classpath option. ;-)
HAHA! :> I've actually got a linux server running, but I do prefer a
windows workstation to a unix/linux workstation. Sorry. I've had
experience with UNIX at university, then RH 7.0 a few years ago, and then
again with 8.0 and with 9.0, then there was Mandrake (not sure what ver but
recent), and man, I've had nothing but pure frustrations/hatred/total
hostilities towards anything computer related during that time. :< I was a
miserable person. I got my mail server up and running in one night on XP
what I couldn't do in two months with RH9.0 and Mandrake. :<<<<< My web
server is a bit different, this time I said I'm sticking with it and not
letting it beat me. So one machine this time lived past the sledge hammer.
:>

Thanks for the info! :> Have a good one.
 
T

Tony Morris

java -classpath ...
also works, Sun just allow the -cp short version
for convenience, but since it is inconsistently
supported, I always use -classpath

The -classpath <arg> option is also provided for convenience; as opposed to
-Djava.class.path=<arg>

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

CLASSPATH 5
javac ignores CLASSPATH variable 3
Classpath 2
classpath and jarfile question 5
java applet classpath 5
Classpath issue from standalone app 2
classpath problem in my machine 5
classpath woes 2

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top