我想问问classpath中设置的两个jar文件%JAVA_HOME%\lib\tools.jar和dt.jar解压缩之后为什么只有sun、javax、com等包,却没有java包,就是最长用的那个包,java.lang什么的究竟在哪?

解决方案 »

  1.   

    在这里 %JAVA_HOME%\jre\lib\rt.jar
      

  2.   

    rt.jar中run time的意思 这个是自动的加载
      

  3.   

    thx a lot.
    但是还想问dt是啥意思呢?develop time?
    rt.jar怎么个自动加载法?
    我看rt.jar中几乎有所有的包,如果rt自动加载,那么CLASSPATH还用设置什么呢?
      

  4.   

    呵呵,昨晚看的:
    classloader至少三种:
    1.The bootstrap class loader2.The extension class loader3.The system class loader (also sometimes called the application class loader)The bootstrap class loader loads the system classes (typically, from the JAR file rt.jar). It is an integral part of the virtual machine and is usually implemented in C. There is no ClassLoader object corresponding to the bootstrap class loader. For example,String.class.getClassLoader()returns null.The extension class loader loads "standard extensions" from the jre/lib/ext directory. You can drop JAR files into that directory, and the extension class loader will find the classes in them, even without any class path. (Some people recommend this mechanism to avoid the "class path from hell," but see the cautionary notes below.)The system class loader loads the application classes. It locates classes in the directories and JAR/ZIP files on the class path, as set by the CLASSPATH environment variable or the -classpath command-line option.core java II
      

  5.   

    java.lang 是所有类会默认自动加载的
      

  6.   

    谢谢superslash,解答很清楚。
    不过我看后,把CLASSPATH变量彻底删了,也可以运行程序,但是当前目录下(就是那个".")的那个默认路径难道也不用设置么?
    而你说的上面的第三种class加载说要在CLASSPATH设置中的目录和jar,zip中搜索class,可是我现在已经没有CLASSPATH了,那么当前目录下的那个class如何加载进来的?
      

  7.   

    CLASSPATH可以用来设置除rt.jar、jce.jar、jsse.jar、charset.jar等引导类(Bootstrap classes)包和dnsns.jar、localedata.jar、sunjce_provider.jar等扩展类(Extension classes)可选包之外的其它包啊,比如:
    Path=.;C:\Program Files\Java\j2sdk1.4.2_09\lib\tools.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\endorsed\xml-apis.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\endorsed\xercesImpl.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.5\lib\servlet-api.jar以下是从J2SE文档中找到的,感觉说的很好!:)
    1、How Classes are Found:
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/findingclasses.htmlThe Java launcher, java, initiates the Java virtual machine. The virtual machine searches for and loads classes in this order:Bootstrap classes - Classes that comprise the Java platform, including the classes in rt.jar and several other important jar files.Extension classes - Classes that use the Java Extension mechanism. These are bundled as .jar files located in the extensions directory.User classes - Classes defined by developers and third parties that do not take advantage of the extension mechanism. You identify the location of these classes using the -classpath option on the command line the preferred method) or by using the CLASSPATH environment variable. (See Setting the Classpath for Windows or Solaris.)
    In effect, these three search paths are joined to form a simple class path. This is similar to the "flat" class path previously used, but the current model has some important differences:It is relatively difficult to accidentally "hide" or omit the bootstrap classes.In general, you only have to specify the location of user classes. Bootstrap classes and extension classes are found "automatically".
    [一般来说,你只需要指定用户类(user classes)的位置,引导类(Bootstrap classes)和扩展类(extension classes,也叫可选包Optional Packages)可以自动被找到。]The tools classes are now in a separate archive (tools.jar) and can only be used if included in the user class path (to be explained shortly).2、Setting the class path:
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/classpath.htmlThe default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.
    [默认的Class Path是当前目录。设置CLASSPATH变量或者在命令行中使用-classpath选项将会覆盖默认设置,也就是说,如果你想在Java类查找路径中包含当前目录,你必须在新设置中包括“.”。比如,Path=.;C:\Program Files\Java\j2sdk1.4.2_09\lib\tools.jar]3、The Java Extension Mechanism
    http://java.sun.com/j2se/1.4.2/docs/guide/extensions/index.html
      

  8.   

    不过我看后,把CLASSPATH变量彻底删了,也可以运行程序,但是当前目录下(就是那个".")的那个默认路径难道也不用设置么?
    而你说的上面的第三种class加载说要在CLASSPATH设置中的目录和jar,zip中搜索class,可是我现在已经没有CLASSPATH了,那么当前目录下的那个class如何加载进来的?======================================================================
    这个问题我也不是很清楚,但是好象跟JDK版本有关,我的1.4也是不用设置.(当前目录的)但是我以前用过的版本不行,也许是1.4及以后版本JVM运行时自动加载当前目录下所有类罢(1.5 is also OK at my computer)