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

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.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/330815.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

线程池的实现

1.创建线程池 API提供了一个工具类叫Executors&#xff0c;可以用它的方法生成不同特点的线程池&#xff0c;返回一个ExecutorService对象。 <1>Executors.newCachedThreadPool() 【池子中默认是空的&#xff0c;最多可以容纳int类型的最大值】 <3>Executors.new…

JSON Web Token (JWT),服务端信息传输安全解决方案

转载自 JSON Web Token (JWT)&#xff0c;服务端信息传输安全解决方案JWT介绍 JSON Web Token(JWT)是一种开放标准(RFC 7519)&#xff0c;它定义了一种紧凑独立的基于JSON对象在各方之间安全地传输信息的方式。这些信息可以被验证和信任&#xff0c;因为它是数字签名的。JWTs可…

thinking-in-java(18) java io

【0】README&#xff1a;本篇文章是以 thinking in java 为基础梳理的&#xff1b; 【18.1.1 目录列表器】 // 传入正则表达式以过滤文件名如 (.*src)* public class DirList {public static void main(String[] args) {File path new File(".");String[] list; i…

并发工具类【线程安全相关的类】

1.Hashtable和ConcurrentHashMap Hashtable&#xff1a;哈希表结构&#xff08;数组链表&#xff09;&#xff0c;线程安全的(同步代码块&#xff0c;效率低) ConcurrentHashMap&#xff1a; jdk7:采用Segment数组[不会扩容] HashEntry[二次哈希计算存入的位置,可扩容]&#…

JSON Web Token (JWT)生成Token及解密实战

转载自 JSON Web Token (JWT)生成Token及解密实战昨天讲解了JWT的介绍、应用场景、优点及注意事项等&#xff0c;今天来个JWT具体的使用实践吧。从JWT官网支持的类库来看&#xff0c;jjwt是Java支持的算法中最全的&#xff0c;推荐使用&#xff0c;网址如下。https://github.co…

java中两个map的融合(两个map有相同字段)

试想这样一个场景&#xff1a; 数据库表中 有 城市信息表 city_tbl&#xff1b; 有院士信息表 ys_tbl &#xff0c;其中院士有城市id字段&#xff08;id&#xff09;&#xff1b; 但是不是所有城市都有院士&#xff1b; 我们想要得到 城市的详细信息&#xff0c;包括院士个数…

网络编程实现

1.网络编程三要素 1.IP地址&#xff1a;网络中设备的唯一标识IPv4: 由4个字节组成&#xff0c;点分十进制表示法IPv6: 由16个字节组成&#xff0c;冒分十六进制表示法"127.0.0.1"本地主机网络地址【用于测试】相关命令&#xff1a;ipconfig: 查看本机在当前网络环境…

通用唯一标识码UUID的介绍及使用

转载自 通用唯一标识码UUID的介绍及使用。什么是UUID&#xff1f; UUID全称&#xff1a;Universally Unique Identifier&#xff0c;即通用唯一识别码。 UUID是由一组32位数的16进制数字所构成&#xff0c;是故UUID理论上的总数为16^32 2^128&#xff0c;约等于3.4 x 10^38。也…

IEEE论文检测的字体未嵌入问题Times New Roman,Bold, Times New Roman,Italic is not embedded解决方法

【1】README 毕业前写了一篇 英文paper&#xff0c; 接受后&#xff0c;需要提交到 IEEE PDF Express 做格式检测&#xff1b;&#xff1b;latex源码中引用了 Visio生成的算法流程图&#xff0c;PDF文件&#xff1b; 谁料&#xff0c;哥子提交上去后&#xff0c;报如下错误&…

类加载器的创建

1.什么是类加载器 <1>概念&#xff1a;类加载器是用来加载类的工具(从硬盘加载到JVM内存) <2>类加载器的加载时机【类在使用时才被加载&#xff0c;不使用不加载】 a.创建类的对象时 b.通过类名调用静态方法时 c.通过反射加载类 <3>3.类加载器的分类 a.启动…

Java 必看的 Spring 知识汇总

转载自 Java 必看的 Spring 知识汇总Spring框架是由于软件开发的复杂性而创建的。Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情。然而&#xff0c;Spring的用途不仅仅限于服务器端的开发。从简单性、可测试性和松耦合性的角度而言&#xff0c;绝大部分Java应用…

Java 截取反斜杠--java使用split拆分特殊字符

orgn link : http://blog.csdn.net/scy411082514/article/details/7987852 Java 截取反斜杠 replaceAll和split &#xff08;“\”&#xff09; 问题解决办法 2009年07月15日 星期三 上午 11:26 xxx.split("\\") 显然得不到想要的结果 正确方法 xxx.split(&qu…

反射的实现

1.获取类的字节码对象 //获取类的字节码对象 public class Demo1 {public static void main(String[] args) throws ClassNotFoundException {//方式1&#xff1a;类名.ClassClass<?> clazz1 Student.class;//方式2&#xff1a;对象名.getClass()Student student new…

thinking-in-java(11) 持有对象

【11.1】泛型和类型安全的容器 &#xff08;1&#xff09;ArrayList<Apple> 中尖括号括起来的是&#xff1a; 类型参数&#xff0c;它指定了这个容器实例可以保存的类型&#xff1b; 【荔枝&#xff1a;有泛型和没有泛型的区别】 class Apple {private static long coun…

JDK9新特性实战:简化流关闭新姿势

转载自 JDK9新特性实战&#xff1a;简化流关闭新姿势。做Java开发的都知道&#xff0c;每个资源的打开都需要对应的关闭操作&#xff0c;不然就会使资源一直占用而造成资源浪费&#xff0c;从而降低系统性能。 关于资源的关闭操作&#xff0c;从JDK7-JDK9有了不少的提升及简化。…

XML配置文件

XML的语法 1.xml是由自定义的标签组成 <开始标签>标签体</结束标签> <自闭合标签/> 2.xml文件的语法 1)必须要有一个文档声明 <?xml version"1.0" encoding"UTF-8" ?>2)只有一个根标签3)特殊字符 如< > & 必须使用…

DevExperience(1710)

【1】Date 和 String 互转 // Date 和 String 互转。public static void main(String[] args) {SimpleDateFormat formatter new SimpleDateFormat("yyyyMMdd");// Date 转 StringString curDateStr formatter.format(new Date());System.out.println("curDat…

Java Jar包的压缩、解压使用指南

转载自 Java Jar包的压缩、解压使用指南什么是jar包 JAR&#xff08;Java Archive&#xff09;是Java的归档文件&#xff0c;它是一种与平台无关的文件格式&#xff0c;它允许将许多文件组合成一个压缩文件。 如何打/解包 使用jdk/bin/jar.exe工具&#xff0c;配置完环境变量后…

枚举的实现

1.枚举的概念 枚举就是把几个固定的常量列举出来。枚举本质上也是一个类&#xff0c;只不过这个类的对象是几个固定的值&#xff0c;不能让外界创建对象【因为其内部的构造方法私有】 2.定义一个枚举类 public enum Week {//枚举项表示Week类的对象&#xff0c;带括号表示使…

think-in-java(17)容器深入研究

注意&#xff1a; 17章接着 11章继续分析 java容器&#xff0c; think-in-java(11) 【17.1】完整的容器分类方法 【容器分类网络解说】 1&#xff09;接口&#xff1a;虚线框&#xff0c;没有实线入边&#xff08;没有实体类继承关系&#xff0c;只有接口继承关系&#xff09…