How Classes are Found 中有说明:(java启动类文件在 rt.jar中, 而 工具类文件在 tools.jar 中) 

How the Java Launcher Finds Classes

The 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 Unix.)

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".
  • 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).

How the Java Launcher Finds Bootstrap Classes

Bootstrap classes are the classes that implement the Java 2 Platform. Bootstrap classes are in the rt.jar and several other jar files in the jre/lib directory. These archives are specified by the value of the bootstrap class path which is stored in the sun.boot.class.path system property. This system property is for reference only, and should not be directly modified.

It is very unlikely that you will need to redefine the bootstrap class path. The nonstandard option, -Xbootclasspath, allows you to do so in those rare cicrcumstances in which it is necessary to use a different set of core classes.

Note that the classes which implement the Java 2 SDK tools are in a separate archive from the bootstrap classes.The tools archive is the SDK's/lib/tools.jar file.The development tools add this archive to the user class path when invoking the launcher. However, this augmented user class path is only used to execute the tool. The tools that process source code, javac and javadoc, use the original class path, not the augmented version. (For more information, see How Javac and Javadoc Find Classes, below.)

How the Java Launcher Finds User Classes (java启动器如何找到用户类)

User classes are classes which build on the Java platform. To find user classes, the launcher refers to the user class path -- a list of directories, JAR archives, and ZIP archives which contain class files.

A class file has a subpath name that reflects the class's fully-qualified name. For example, if the class com.mypackage.MyClass is stored under /myclasses, then /myclasses must be in the user class path and the full path to the class file must be /myclasses/com/mypackage/MyClass.class. If the class is stored in an archive named myclasses.jar, then myclasses.jar must be in the user class path, and the class file must be stored in the archive ascom/mypackage/MyClass.class.

The user class path is specified as a string, with a colon (:) separating the class path entries on Solaris, and a semi-colon (;) separating entries on Microsoft Windows systems. The java launcher puts the user class path string in the java.class.path system property. The possible sources of this value are:

  • The default value, ".", meaning that user class files are all the class files in the current directory (or under it, if in a package).
  • The value of the CLASSPATH environment variable, which overrides the default value.
  • The value of the -cp or -classpath command line option, which overrides both the default value and the CLASSPATH value.
  • The JAR archive specified by the -jar option, which overrides all other values. If this option is used, all user classes must come from the specified archive.

为什么jdk的CLASSPATH环境变量需要设置rt.jar 和 tools.jar相关推荐

  1. JDK 1.6环境变量的设置

    E:/Java/jdk1.6.0_02这是我的安装目录 . 首先右键点我的电脑.打开属性.然后选择"高级"里面的"环境变量",在新的打开界面中的系统变量里需要设 ...

  2. JDK安装及环境变量配置

    JDK安装及环境变量配置 1.下载JDK 2.配置环境变量 JAVA_HOME 设置 PATH设置 CLASSPATH 设置 测试JDK是否安装成功 流行JAVA开发工具 1.下载JDK 首先我们需要 ...

  3. Win7下JDK环境变量的设置

    JDK并不像Microsoft阵营vs那样智能,安装好后所有的东西都给你配置好了,我们还没需要手动配置很多东西 首先说为什么要配置JDK的环境变量在任何路径下识别java命令和java类 配置分为2个 ...

  4. JDK环境变量的设置

    2019独角兽企业重金招聘Python工程师标准>>> 系统变量与用户变量中path:在用户变量中设置的path只有在重启之后才可以生效,而系统变量中path设置完成后就可以实现:计 ...

  5. 1.2 JDK安装与环境变量设置

    我们会以Java语言来进行脚本编写,所以需要进行JDK安装以及必要的环境变量设置.本书会使用JDK 8的版本,而不会使用JDK 9(太新的有的软件不兼容). 可以直接取Oracle官网选择相应的JDK ...

  6. Eclipse 如何安装,以及jdk如何设定环境变量

    Eclipse 如何安装,以及jdk如何设定环境变量 20 [ 标签:eclipse jdk,jdk,变量 ] Eclipse 如何安装,以及jdk如何设定环境变量 有个图解图解就好了,谢谢 Harr ...

  7. WIN7 64位系统安装JDK并配置环境变量

    首先,下载JDK安装包,到官网http://www.oracle.com/technetwork/java/javase/downloads/index.html进行下载,点左边的Java Platf ...

  8. Windows—JDK安装与环境变量配置

    本文介绍JDK的安装与环境变量配置. 工具/原料 JDK1.8.0_65 WIN7 32bit jdk-8u65-windows-i586.exe 方法/步骤 安装JDK 选择安装目录 安装过程中会出 ...

  9. Java环境变量的设置

    1.计算机->属性->高级系统设置->环境变量 2.设置JAVA_HOME和path,1.5之后的JDK可以不设置classpath 3.JAVA_HOME的路径是JDK的安装路径 ...

最新文章

  1. 开源交换需新框架 技术团队也待整合
  2. python使用matplotlib, seaborn画图时候的数据加载
  3. java表达式类型自动提升
  4. SpringCloud(第 025 篇)Zuul 路由后面的微服务挂了后,Zuul 提供了一种回退机制来应对熔断处理...
  5. 江苏省事业单位计算机入面分数线,2020江苏事业单位统考周日笔试,考多少分进面?...
  6. Java线程:线程的调度-优先级
  7. gradle文件不识别_识别Gradle约定
  8. [渝粤教育] 江西师范大学 创业社团功能与自我发展 参考 资料
  9. 台积电一季度营收接近170亿美元 再创新高
  10. MySqlBackup.NET——用于C#,VB.NET,ASP.NET的MySQL备份解决方案
  11. CentOS6.5和RedHat6.5下以rpm方式安装mysql-5.6.20
  12. 在EF4.1的DBContext中实现事务处理(BeginTransaction)和直接执行SQL语句的示例
  13. 或许是介绍Android Studio使用Git最详细的文章
  14. 深度学习关于分布式任务调度平台XXL-JOB框架详解
  15. 支付宝 java 签名_支付宝APP支付(Java后台生成签名具体步骤)
  16. Ubuntu操作系统漏洞扫描和分析
  17. 数仓治理:数据地图长什么样?
  18. 基于墨刀实现的原型系统:一款简易的读书软件
  19. 面试官最想听哪些话?
  20. 爬取(明星网)明星面部数据

热门文章

  1. CodeCraft-20 (Div. 2) D. Nash Matrix 构造 + dfs
  2. Coding Contest HDU - 5988
  3. [2020-11-30 contest]数列(矩阵加速),秘密通道(dijkstra最短路)小X游世界树(换根dp),划分(数学)
  4. codeforces1552 D. Array Differentiation(思维+暴力)
  5. P6240 好吃的题目(分治+背包)
  6. codeforces gym-101745 C-Infinite Graph Game 分块
  7. 常用公有云接入——阿里
  8. 漫画:删去k个数字后的最小值
  9. Ehcache介绍及整合Spring实现高速缓存
  10. Spring的核心模块解析