javac ignores CLASSPATH variable

Discussion in 'Java' started by void.no.spam.com@gmail.com, Jan 18, 2007.

  1. Guest

    I have the JDK 1.4.2_13 installed on Linux, and have my CLASSPATH
    environment variable set correctly (it looks correct when I do the
    "set" command).

    When I try to compile a java class using the command:
    javac myClass.java
    it tells me that a certain package does not exist, even though that
    package does exist in the CLASSPATH.

    But when I compile the java class using the command:
    javac -classpath [the same thing in my CLASSPATH env var] myClass.java
    then it works fine.

    Why is javac ignoring my CLASSPATH environment variable?
     
    , Jan 18, 2007
    #1
    1. Advertising

  2. wrote:
    ....
    > Why is javac ignoring my CLASSPATH environment variable?


    I cannot immediately say, but note that Sun
    has recommended for some time now, that
    resources *not* be added to the CP env. var.,
    but instead added to the project at compile or
    run-time. Exactly as you report works for you.

    I take it you are not using ant?
    (It might be a better alternative to your
    compilation and build requirements - I
    swore by the 'command line' till around
    8 months ago - but now I am finding I
    use ant for anything that goes beyond the
    'default package'*.)

    * Suitable only for test/toy codes. But then
    again, even a lot of my test codes make it
    into packages (when I have them working,
    and want to show others) and thereafter
    gain a build.xml file.

    Andrew T.
     
    Andrew Thompson, Jan 18, 2007
    #2
    1. Advertising

  3. On 17 Jan 2007 17:30:58 -0800, wrote:
    > I have the JDK 1.4.2_13 installed on Linux, and have my CLASSPATH
    > environment variable set correctly (it looks correct when I do the
    > "set" command).


    [...]

    > Why is javac ignoring my CLASSPATH environment variable?


    Exactly what mechanism did you use to set the CLASSPATH? Does it still
    look correct if you do this instead:

    printenv CLASSPATH

    If not, then it isn't set properly. If you're using Bash or other
    descendent to Bourne shell, then the correct commands are:

    CLASSPATH=<something>
    export CLASSPATH

    Or

    export CLASSPATH=<something>

    If your shell is tcsh or one of its friends, use setenv (not set).

    For other shells, other rules apply. Read the shell documentation.

    /gordon

    --
    [ don't email me support questions or followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Jan 18, 2007
    #3
  4. Guest

    Gordon Beaton wrote:
    > On 17 Jan 2007 17:30:58 -0800, wrote:
    > > I have the JDK 1.4.2_13 installed on Linux, and have my CLASSPATH
    > > environment variable set correctly (it looks correct when I do the
    > > "set" command).

    >
    > [...]
    >
    > > Why is javac ignoring my CLASSPATH environment variable?

    >
    > Exactly what mechanism did you use to set the CLASSPATH? Does it still
    > look correct if you do this instead:
    >
    > printenv CLASSPATH
    >
    > If not, then it isn't set properly. If you're using Bash or other
    > descendent to Bourne shell, then the correct commands are:
    >
    > CLASSPATH=<something>
    > export CLASSPATH
    >
    > Or
    >
    > export CLASSPATH=<something>
    >
    > If your shell is tcsh or one of its friends, use setenv (not set).
    >
    > For other shells, other rules apply. Read the shell documentation.


    Gordon, I had been doing "CLASSPATH=<something>" in my .bashrc file.
    But now I'm doing "export CLASSPATH=<something>" and it works! Thank
    you!
     
    , Jan 18, 2007
    #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. Ronald Fischer

    Ant javac : How to print classpath?

    Ronald Fischer, Sep 18, 2003, in forum: Java
    Replies:
    1
    Views:
    17,672
    Wayne Berke
    Sep 19, 2003
  2. Gabe
    Replies:
    3
    Views:
    1,119
  3. Miss Michelle. Heigardt
    Replies:
    8
    Views:
    143,911
    abbinv
    Apr 9, 2011
  4. drunken_wizard
    Replies:
    1
    Views:
    11,476
    Tris Orendorff
    Mar 23, 2006
  5. Replies:
    2
    Views:
    1,158
    Mike Schilling
    Mar 2, 2008
Loading...

Share This Page