classpath question

Jeff Sturm
Thu Sep 14 09:30:00 GMT 2000

Tom Tromey wrote:
> You can already set java.class.path at link time with -D.

True, but java.class.path is a system property.  If I override it I can't expect
the classloader to honor it, any more than I should expect
System.getProperties().put("user.dir", "/") to change my working directory.

> Maybe we
> should set the default in the compiler at link time?  Would that be
> sufficient?

I think so.  The command

$ gcj -Djava.class.path=/tmp --main=CPTest -o cptest

just happens to do that.  It also checks CLASSPATH at runtime and prepends it,

$ CLASSPATH=/usr/share/java ./cptest
classpath = /usr/share/java:/tmp
$ ./cptest
classpath = /tmp

Note is absent, which seems wrong to me.

Ideally, I'd just like the gcj --classpath arg to persist in the compiled
executable, in other words:

$ gcj --classpath=/tmp ...

would effectively do:

$ gcj -Djava.class.path=/tmp --classpath=/tmp ...

Later we could add some option to compile selected resources into the program
image.  I'm undecided whether it still makes sense to check the environment
(i.e. CLASSPATH) in that case.

Jeff Sturm

More information about the Java mailing list