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(不区分大小写)里面查找. ...
随机推荐
- Android权限解释
属性 说明 android.permission.ACCESS_CHECKIN_PROPERTIES 允许读写访问 "properties"表在checkin数据库中,改值可以修改 ...
- NoSQL注入的分析和缓解
本文要点介绍: 1.了解针对NoSQL的新的安全漏洞 2.五类NoSQL攻击手段,比如重言式.联合查询.JavaScript 注入.背负式查询(Piggybacked queries),以及跨域违规 ...
- cuda编程学习4——Julia
书上的例子编译会有错误,修改一下行即可. __device__ cuComplex(float a,float b):r(a),i(b){} /* ========================== ...
- iOS开发之UIDevice通知
UIDevice类提供了一个单例对象,它代表着设备,通过它可以获得一些设备相关的信息,比如电池电量值(batteryLevel).电池状态(batteryState).设备的类型(model,比如iP ...
- 走入PHP-数据类型和字符串语法
PHP支持8种原始数据类型 四种标量类型: boolean | integer | float(as double) | string 两种复合类型: array | object 两种特殊类型 re ...
- stl1
#include<iostream> #include<map> #include<string> using namespace std; map<st ...
- iOS9,10没有问题,iOS8上面一登录就崩溃,原因Assets的问题
在项目中开发中,打包成一个ipa的包,发现iOS9,10,运行非常流畅,iOS8上面一运行就崩溃,找了好久,才找到原因竟然是Assets的问题,一开始我把ipa包放在蒲公英上面托管扫码下载的,用iTu ...
- 原创SQlServer数据库生成简单的说明文档小工具(附源码)
这是一款简单的数据库文档生成工具,主要实现了SQlServer生成说明文档的小工具,目前不够完善,主要可以把数据库的表以及表的详细字段信息,导出到 Word中,可以方便开发人员了解数据库的信息或写技术 ...
- Windows下检测文件名大小写是否匹配
跨平台开发有一个众所周知,但因为只是偶尔受到困扰,一般人不会在意的问题,就是windows对文件名大小写不敏感,而其他平台对文件名大小写敏感.因此可能出现在windows平台开发时一切正常,但部署/打 ...
- sqoop 操作从hdfs 导入到mysql中语句
将hdfs下/dw/dms/usr_trgt下的文件导入到mysql中test数据库下usr_trgt表中 sqoop-export --connect jdbc:mysql://mysqlDB: ...