javac ignores CLASSPATH variable

G

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?
 
A

Andrew Thompson

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.
 
G

Gordon Beaton

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
 
G

Guest

Gordon said:
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!
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top