Linux 下面设置JavaCLASSPATH变量
2016-04-20 00:00
323 查看
摘要: Linux 下面设置JavaCLASSPATH变量
除了把需要的jar都一一列举之外,还可以考虑使用通配符。
The corresponding physical file structure is :
We should use the following command-line option:
or alternatively:
或者
可能有很多人想不明白,我直接写成如下不就可以了吗?
可是事实证明这样写并不可以。
为什么呢?官方文档上面这样说
A class path entry that contains an asterisk (*) does not match class files. To match both classes and JAR files in a single directory
Subdirectories are not searched recursively. For example,
The order in which the JAR files in a directory are enumerated in the expanded class path is not specified and may vary from platform to platform and even from moment to moment on the same machine. A well-constructed application should not depend upon any particular order. If a specific order is required, then the JAR files can be enumerated explicitly in the class path.
Expansion of wild cards is done early, before the invocation of a program's main method, rather than late, during the class-loading process. Each element of the input class path that contains a wildcard is replaced by the (possibly empty) sequence of elements generated by enumerating the JAR files in the named directory. For example, if the directory
The
参考博文:
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html
http://blog.csdn.net/bluishglc/article/details/9972951
Linux 下面设置JavaCLASSPATH变量
设置了classpath 将会让程序执行的更快export PATH="$JAVA_HOME/bin:"$PATH export FILE_HOME=/root/test echo $FILE_HOME export CLASSPATH=.:$FILE_HOME/axis-1.4.jar:$JAVA_HOME/jre/lib/rt.jar:$FILE_HOME/axis-jaxrpc-1.4.jar:$FILE_HOME/axis-saaj-1.4.jar:$FILE_HOME/axis-wsdl4j-1.5.1.jar:$FILE_HOME/log4j-1.2.16.jar:$FILE_HOME/commons-logging-1.1.1.jar:$FILE_HOME/commons-discovery-0.2.jar javac $FILE_HOME/TestTogate.java java -cp $CLASSPATH -Dcatalina.home="$FILE_HOME" TestTogate
除了把需要的jar都一一列举之外,还可以考虑使用通配符。
例如如下结构:
Now, suppose the program uses a supporting library enclosed in a Jar file called supportLib.jar, physically in the directory D:\myprogram\lib\.The corresponding physical file structure is :
D:\myprogram\ | ---> lib\ | ---> supportLib.jar | ---> org\ | --> mypackage\ | ---> HelloWorld.class ---> SupportClass.class ---> UtilClass.class
We should use the following command-line option:
java -classpath D:\myprogram;D:\myprogram\lib\supportLib.jar org.mypackage.HelloWorld
or alternatively:
set CLASSPATH=D:\myprogram;D:\myprogram\lib\supportLib.jar java org.mypackage.HelloWorld
或者
java -classpath D:\myprogram;D:\myprogram\lib\* org.mypackage.HelloWorld
可能有很多人想不明白,我直接写成如下不就可以了吗?
java -classpath D:\myprogram\*;D:\myprogram\lib\* org.mypackage.HelloWorld
可是事实证明这样写并不可以。
为什么呢?官方文档上面这样说
Class Path Wild Cards
Class path entries can contain the base name wildcard character (*), which is considered equivalent to specifying a list of all of the files in the directory with the extension.jaror
.JAR. For example, the class path entry
mydir/*specifies all JAR files in the directory named
mydir. A class path entry consisting of * expands to a list of all the jar files in the current directory. Files are considered regardless of whether they are hidden (have names beginning with '.').
A class path entry that contains an asterisk (*) does not match class files. To match both classes and JAR files in a single directory
mydir, use either
mydir:mydir/*or
mydir/*:mydir. The order chosen determines whether the classes and resources in
mydirare loaded before JAR files in
mydiror vice versa.
Subdirectories are not searched recursively. For example,
mydir/*searches for JAR files only in
mydir, not in
mydir/subdir1,
mydir/subdir2, and so on.
The order in which the JAR files in a directory are enumerated in the expanded class path is not specified and may vary from platform to platform and even from moment to moment on the same machine. A well-constructed application should not depend upon any particular order. If a specific order is required, then the JAR files can be enumerated explicitly in the class path.
Expansion of wild cards is done early, before the invocation of a program's main method, rather than late, during the class-loading process. Each element of the input class path that contains a wildcard is replaced by the (possibly empty) sequence of elements generated by enumerating the JAR files in the named directory. For example, if the directory
mydircontains a.jar, b.jar, and c.jar, then the class path
mydir/*is expanded into
mydir/a.jar:mydir/b.jar:mydir/c.jar, and that string would be the value of the system property java.class.path.
The
CLASSPATHenvironment variable is not treated any differently from the
-classpathor
-cpoptions. Wild cards are honored in all of these cases. However, class path wild cards are not honored in the Class-Path jar-manifest header.
参考博文:
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html
http://blog.csdn.net/bluishglc/article/details/9972951
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- Linux 下无损图片压缩小工具介绍