以前发布了关于java开发环境配置的文章,通过与网友的交流,我了解到在jdk1.5之后,java开发环境配置的时候,确实不须要对classpath进行配置,但市面上的书籍,以及一些博客、仍是老一套,继续推荐配置classpath,而且关于不须要配置classpath网络上没有什么完整细致,能使人信服的答案,因此我查阅了一些资料以及与别人交流,今天和你们分享一下这些内容。java
.;%Java_Home%\bin;%Java_Home%\lib\dt.jar;%Java_Home%\lib\tools.jar网络
Java_Home表明了咱们jdk的路径app
当咱们配置classpath后,系统会根据咱们所配置的classpath加载类工具
例如:在咱们使用javac命令编译程序时,系统加载tools.jar其实就封装了下面这样一条命令spa
javac XXX.java3d
java -Classpath=%JAVA_HOME%\lib\tools.jar xx.xxx.Main XXX.javaorm
固然tools的功能可不止这一点,可是确实它为咱们提供了不少便利cdn
在JDK1.5之后,classpath并非必须配置了,在JDK1.5以前,是没有办法在当前目录下加载类的(找不到 JDK目录下lib文件夹中的.jar文件),因此咱们须要经过配置classpath,但JDK1.5以后,JRE能自动搜索目录下类文件,而且加载dt.jar和tool.jar的类。blog
The class path tells the JDK tools and applications where to find third-party and user-defined classes that are not extensions or part of the Java platform. See The Extension Mechanism atip
类路径告诉JDK工具和应用程序在哪里能够找到第三方和用户定义的类,这些类既不是Java平台的扩展,也不是Java平台的一部分。参见扩展机制
If you upgrade from an earlier release of the JDK, then your startup settings might include CLASSPATH settings that are no longer needed. You should remove any settings that are not application-specific, such as classes.zip. Some third-party applications that use the Java Virtual Machine (JVM) can modify your CLASSPATH environment variable to include the libraries they use. Such settings can remain.
若是您从JDK的早期版本升级,那么您的启动设置可能包括再也不须要的类路径设置。您应该删除任何与应用程序无关的设置,好比classes.zip。一些使用Java虚拟机(JVM)的第三方应用程序能够修改类路径环境变量,以包含它们使用的库。这样的设置能够保留。
You can change the class path by using the -classpath or -cp option of some Java commands when you call the JVM or other JDK tools or by using the CLASSPATH environment variable. See JDK Commands Class Path Options. Using the -classpath option is preferred over setting the CLASSPATH environment variable because you can set it individually for each application without affecting other applications and without other applications modifying its value. See CLASSPATH Environment Variable.
在调用JVM或其余JDK工具时,可使用一些Java命令的-classpath或-cp选项,或者使用CLASSPATH环境变量,来更改类路径。参见JDK命令类路径选项。使用-classpath选项优于设置CLASSPATH环境变量,由于您能够为每一个应用程序单独设置它,而不影响其余应用程序,也不须要其余应用程序修改它的值。参见CLASSPATH环境变量。
经过官方的文档说明咱们能够看到,rt.jar和tool.jar这两种属于java平台自身的包就不须要添加到classpath中,只有一些第三方类或者自定义类须要,也并不推荐使用配置CLASSPATH的方法,更推荐使用-classpath选项
在JDK1.5以后的版本,配置Java环境变量的时候咱们再也不须要配置classpath,只须要配置Java_Home以及path便可!
若是内容中有什么不足,或者错误的地方,欢迎你们给我留言提出意见, 蟹蟹你们 !_
若是能帮到你的话,那就来关注我吧!
在这里的咱们素不相识,却都在为了本身的梦而努力 ❤
一个坚持推送原创Java技术的公众号:理想二旬不止