Java的CLASSPATH
在JDK安装好后,要设置两个变量Path和Classpath,Path是操作系统要求的,这里不谈了,而classpath是Java虚拟机要求的这里做一个详细的解释。
一、classpath的作用
==============
The class path is the path that the Java runtime environment searches for classes and other resource files. The class search path (more commonly known by the shorter name, "class path") can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting the CLASSPATH environment variable. The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value.
二、classpath如何设置
==============
windows下的设置很简单。
右键“计算机”->属性->高级系统设置->系统属性对话框->高级选项卡->环境变量,在调出的环境变量对话框中有两种环境变量:1、用户变量,2、系统变量。同一个环境变量既可以在用户变量中设置也可以在系统变量中设置,比如Path环境变量。这两者的区别是,系统环境变量对系统中的每一个用户都有效,而用户环境变量只对当前用户有效。
具体来说就是在读取环境变量的时候,如果用户变量和系统变量中同时设置了同一个变量,则先读取在系统变量中设置的内容,然后再读取用户变量中设置的内容。
主要说一下linux下的设置。
linux下环境变量设置有两个地方。一个是在/etc/profile文件中,这个文件中设置的环境变量是系统级别的,相当于windows中的系统变量;另一个地方是~/.bash_profile,这个文件中设置的环境变量是用户级别的,相当于windows中的用户变量。
同一个变量在/etc/profile和~/.bash_profile中同时设置时,当echo $variableName的时候先读取/etc/profile中的值然后读取~/.bash_profile中的值,最后组合成最终的输出。
三、classpath的内容
===============
classpath的内容就是哪些可以设置到classpath中去。
Class paths to the .jar, .zip or .class files. Each classpath should end with a filename or directory depending on what you are setting the class path to:
- For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.
- For .class files in an unnamed package, the class path ends with the directory that contains the .class files.
- For .class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name).
Multiple path entries are separated by semi-colons. With the set command, it's important to omit spaces from around the equals sign (=).
The 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.
Classpath entries that are neither directories nor archives (.zip or .jar files) nor * are ignored.
四、其他问题
===============
classpath这个环境变量在设置的时候,应该写成大写还是写成小写呢?
这个问题在linux下没有疑问,因为linux下的环境变量约定都是大写的,而且linux下环境变量是区分大小写的,所以在linux下应该写成大写的。
但是这个问题在windows下是有区别的。因为windows下的环境变量不区分大小写,所以原则上写成大写或者小写都可以。一般情况下设置的时候还是推荐设置成大写的,原因是其他的软件比如ant、tomcat等是要求CLASSPATH为大写的,所以为了将来和这些软件良好的配合,最好还是写成大写的。
另外,关于Classpath设置,oracle的JDK团队有一个解释:http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html , 需要的时候可以详细参考。
Java的CLASSPATH的更多相关文章
- java 获取classpath下文件多种方式
java 获取classpath下文件多种方式 一:properties下配置 在resources下定义server.properties register.jks.path=classpath\: ...
- java获取classpath文件路径空格转变成了转义字符%20的问题
java获取classpath文件路径空格转变成了转义字符%20的问题 这个问题很纠结,服务器的文件路径带有空格,空格被转化是%20了,悲剧就出现了 下面展示一段代码String path = get ...
- java classpath import package 机制 @Java的ClassPath, Package和Jar
java classpath import package 机制 從一個簡單的例子談談package與import機制 基本原則:為什麼需要將Java文件和類文件切實安置到其所歸屬之Package ...
- java中classPath和Xpath问题
java中classPath和Xpath问题 今天遇到一个问题想获取classpath对应的目录,开始还以为java源代码可以像spring配置文件.xml中一样通过classpath:来获取对应的路 ...
- 谈谈Java的classpath
Java之ClassPath 大家刚开始写Java代码的时候,如果使用Eclipse作为IDE,同时需要引用其他的类库,一般会有如下操作 在工程中新建lib目录 将jar包复制到lib目录下 右键单击 ...
- Java中classpath配置
Java中classpath配置 一.DOS常用命令 二.DOS常用命令实例 2.1 转换目录 cd 1.6* 2.2 删除文件 del 删除文件(windows删除从里往外删) del *.txt ...
- 终于理解java的classpath!
JAVA 的CLASSPATH 上面这样是可以的!!!!哇, 再也不会出现编译或是运行的时候,class 找不到的问题了.终于明白为什么了. java -cp /ysr/my-app P 这条命 ...
- Java的CLASSPATH,趁还没忘赶紧写点
咳咳,睡眠不足加上年龄增长,真的赶脚记忆力不行啦. 接触Java以来,对于环境配置就是按照网上的教程,一路复制粘贴,也没啥想法; 最近决定啃啃ThinkInJava,没看两章就看到这CLASSPATH ...
- JAVA获取CLASSPATH路径
ClassLoader 提供了两个方法用于从装载的类路径中取得资源: public URL getResource (String name); public InputStream getResou ...
- java之classpath到底是什么
如果你输入一个命令,比如java那么系统是如何找到这个命令的呢?按照顺序,系统先在当前目录搜索是否有java.exe, java.bat 等. 如果没有,就得到系统的PATH(不区分大小写)里面查找. ...
随机推荐
- (23)IO之打印流 PrintStream & Printwriter
PrintStream PrintStream可以接受文件和其他字节输出流,所以打印流是对普通字节输出流的增强,其中定义了很多的重载的print()和println(),方便输出各种类型的数据. Pr ...
- Linux-ubuntu安装过程讲解
前言也不准备介绍Linux是什么,为什么要安装ubuntu?相信你能够看到这篇文章也知道自己想要做什么. 一,准备工具 1.VMwareWorkstation虚拟机 下载地址:https://my.v ...
- 【VB超简单入门】五、基本输出输入
之前讲了VB IDE的基本操作和概念,接下来要开始将VB语言的编程了. 程序最重要的部分是输出和输入,输入数据,经过计算机处理,再输出结果.本文将介绍两种最基本的输出输入方法,分别是Print.Msg ...
- Jenkis Editable Email Notification Plugin 使用介绍
Jenkis Editable Email Notification Plugin 使用介绍 前言 Jenkins本身提供的Email插件功能实在有限,只能提供当前Job的基本信息,比如成功.失败以及 ...
- 《InsideUE4》UObject(五)类型系统信息收集
在一起!在一起! 引言 前文中我们阐述了类型系统构建的第一个阶段:生成.UHT分析源码的宏标记并生成了包含程序元信息的代码,继而编译进程序,在程序启动的时候,开始启动类型系统的后续构建阶段.而本文我们 ...
- webstorm中关于vue的一些问题
在进行vue开发中,我使用了webstorm,但是过程坎坷艰辛,遇到了很多问题,我将问题和解决方案贴上,以作参考. 1.vue项目部署在webstorm中,第一个遇到的问题是,webstorm卡住了, ...
- mvalidator手机端校验
官网地址:https://github.com/efri-yang/mobileValidate#%E5%8F%82%E6%95%B0 使用方法: html如下: <li class=" ...
- 原生JS实现弹出窗口的拖拽
上一篇说了一下弹出窗口功能的实现思路,一般情况下紧接着就会需要做到弹窗的移动,当然现在有很插件.库比如hammer可以使用,效率也非常好.但我觉得还是有必要了解一下原生JS的实现思路及方式,如下: 思 ...
- 神奇的marquee--滚动的文字
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- (iOS)私有API的使用(原创)
最近在做企业级程序,需要搞设备的udid等信息,但是ios7把udid私有化了,不公开使用.所以研究了一下ios的私有api. 调查了一下文章,发现这方面的文章不多,国内更是不全,高手们都懒得写基础教 ...