CLASSPATH, -cp and -classpath misunderstanding?

Discussion in 'Java' started by Flip, Feb 9, 2004.

  1. Flip

    Flip Guest

    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.
    Flip, Feb 9, 2004
    #1
    1. Advertising

  2. Flip wrote:
    > ..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. ;-)

    --
    Andrew Thompson
    * http://www.PhySci.org/ Open-source software suite
    * http://www.PhySci.org/codes/ Web & IT Help
    * http://www.1point1C.org/ Science & Technology
    Andrew Thompson, Feb 9, 2004
    #2
    1. Advertising

  3. Flip

    Flip Guest

    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.
    Flip, Feb 9, 2004
    #3
  4. Flip

    Tony Morris Guest


    > 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)
    Tony Morris, Feb 9, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabe
    Replies:
    3
    Views:
    1,055
  2. Tino Lange
    Replies:
    5
    Views:
    290
    Peter Otten
    Jan 20, 2006
  3. Replies:
    2
    Views:
    732
  4. Broeisi

    arrays and strings misunderstanding...

    Broeisi, Feb 16, 2006, in forum: C Programming
    Replies:
    6
    Views:
    324
    Antonio Contreras
    Feb 16, 2006
  5. Replies:
    2
    Views:
    1,084
    Mike Schilling
    Mar 2, 2008
Loading...

Share This Page