Thursday, January 25, 2007

classpath vs. bootclasspath

From the high level, the bootclasspath is a special classpath which
will be used by jvm when the jvm is created and no another action
needs to be done this time.

for example, javac -bootclasspath d:\libs\jars\ant.jar hello.java
it happens: 致命错误:在类路径或引导类路径中找不到软件包 java.lang
the reason is: I specify the bootclasspath to a ant.jar rather than
use the jvm's default setting to the rt.jar.

javac -bootclasspath d:\libs\jars\ant.jar -cp ../rt.jar hello.java
it works. the javac first search the bootclasspth, it failed to find
java.lang, then it try to locate it in classpath, it successed.

--updated
并且,classpath只是一个jvm寻找要加载的类,并且是真正需要用到的类的路径,而不是说要把path上的所有类都加载进去,这也是jvm的Lazy ClassLoad方式.

针对javac编译器,有一个特殊的CLASSPATH: java.lang.*; 这个是默认要加载到jvm中去的。这里面的类通常是core的类,由jvm直接控制其加载。

No comments: