简体   繁体   English

如何中断(用于测试)Java类路径环境变量?

[英]How do I break(for testing) the Java classpath environment variables?

I am working on understanding how Java's import/classpath situation works. 我正在努力了解Java的import / classpath情况如何工作。 I want to produce aa compilation error, so I said 'let me try fiddling with the Java environment variables' (like making JAVA_HOME become JAV_HOM or etc). 我想产生一个编译错误,所以我说“让我尝试摆弄Java环境变量”(例如使JAVA_HOME变为JAV_HOM等)。

在此处输入图片说明 But it seems that it won't work. 但似乎无法正常工作。 Everything compiles fine. 一切都编译良好。 Does it matter that I'm using drJava? 使用drJava是否重要? I even tried restarting, but that didn't do it. 我什至尝试重新启动,但没有成功。

Fiddling with JAVA_HOME is unlikely to break the classpath. 摆弄JAVA_HOME不太可能破坏类路径。

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. JAVA_HOME环境变量主要用于告诉您的代码(如果需要知道)以及Java安装所在的任何第三方工具。 The Java installation (eg the java and javac tools) pay no attention to it. Java安装(例如javajavac工具)不关心它。 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. 运行这些命令时,将隐式给出安装位置……它是您正在运行的Java工具的祖父母目录。

Secondly, the stuff in the installation that might not be found (eg the "rt.jar" and "tools.jar" files) are actually on the "boot classpath" not the regular classpath. 其次,安装中可能找不到的内容(例如“ rt.jar”和“ tools.jar”文件)实际上位于“引导类路径”上,而不是常规类路径上。 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. 现在,我不知道drJava如何管理其类路径。 It might pay attention to the CLASSPATH environment variable, but I wouldn't be surprised if it ignores it. 它可能会注意CLASSPATH环境变量,但是如果忽略它,我不会感到惊讶。 (IDE's typically manage the classpath their own way, based on project structures and the like.) (IDE通常根据项目结构等以自己的方式管理类路径。)

If you want to experiment like this, you'd be better off running java and javac from the command line. 如果要进行这样的实验,最好从命令行运行javajavac 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. 对于这些,类路径由-jar选项(以及JAR清单中的内容),- -cp选项或CLASSPATH环境变量确定。 This is described in the online manual for the java command. 有关java命令的在线手册中对此进行了描述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM