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(不区分大小写)里面查找. ...
随机推荐
- ADO.NET温习(一)
ADO.NET概述 本节复习如何使用ADO.NET访问C#程序中的数据,主要介绍如何使用SqlConnection类和OleDbConnection类连接数据库,以及断开与数据库连接.深入讨论命令对象 ...
- YARN 命令总结
起因:YARN 使用capability schedule queue调度container,spark 的app卡死在YARN的队列里面无法出来,无奈请教大神时,可用[yarn applicatio ...
- 解决mac os下mcss命令报错:env: node\r: No such file or directory
标题无“转载”即原创文章,版权所有.转载请注明来源:http://besteam.im/blogs/article/31/. 我一直对字符界面有抵触感,即使会用vim,我的linux脚本(python ...
- Linux之nc命令详解
nc是一个强大的网络工具,可以通过yum安装 [root@LB2 ~]# which nc /usr/bin/which: no nc in (/usr/local/sbin:/usr/local/b ...
- 虚拟机Linux 的一些基础命令和注释
cd命令 cd ==回到初始,主目录 cd - ==回到上一级目录交替 cd ~ ==回到root家目录 cd . ==当前目录 cd .. ==进入上一级目录 ls命令 ls == ...
- POJ1185炮兵阵地【动态规划】
炮兵阵地 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 26892 Accepted: 10396 Descriptio ...
- 【转】air调用windows自带的虚拟键盘
原文:http://bbs.9ria.com/blog-73243-19560.html 最近在做一个东西,需要用到虚拟键盘.刚开始准备用as3开发一套,结果突然想起来windows有个自带的虚拟键盘 ...
- c++内存优化:二级间接索引模式内存池
/********************************************************* 在一些不确定内存总占用量的情形下,频繁的使用new申请内存,再通过链表 进行索引似 ...
- JavaScript原生Array常用方法
JavaScript原生Array常用方法 在入门Vue时, 列表渲染一节中提到数组的变异方法, 其中包括push(), pop(), shift(), unshift(), splice(), so ...
- js遍历(获取)ul中的li
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...