Pergunta

I am working on understanding how Java's import/classpath situation works. I want to produce a a compilation error, so I said 'let me try fiddling with the Java environment variables' (like making JAVA_HOME become JAV_HOM or etc).

enter image description here But it seems that it won't work. Everything compiles fine. Does it matter that I'm using drJava? I even tried restarting, but that didn't do it.

Foi útil?

Solução

Fiddling with JAVA_HOME is unlikely to break the classpath.

The JAVA_HOME environment variable is primarily used to tell your code (if needs to know) and any 3rd party tools where the Java installation is located. The Java installation (e.g. the java and javac tools) pay no attention to it. When you run these commands, you implicitly give the location of the installation ... it is the grandparent directory of the Java tool you are running.

Secondly, the stuff in the installation that might not be found (e.g. the "rt.jar" and "tools.jar" files) are actually on the "boot classpath" not the regular classpath. The bootclasspath is formed implicitly by the relevant tools ... unless you explicitly override it via command line options etc.


Now I don't know how drJava manages its classpath. It might pay attention to the CLASSPATH environment variable, but I wouldn't be surprised if it ignores it. (IDE's typically manage the classpath their own way, based on project structures and the like.)

If you want to experiment like this, you'd be better off running java and javac from the command line. For these, the classpath is determined by either the -jar option (and what is in the JAR manifest), the -cp option, or the CLASSPATH environment variable. This is described in the online manual for the java command.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top