在java 1.5的时候,我还得写bash脚本去loop获得所有的jar,然后写到classpath下面,现在换到1.6,发现有个classpath wildcard,原来classpath也有通配符
看
这里
引用
Class path entries can contain the basename wildcard character *, which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For example, the class path entry foo/* specifies all JAR files in the directory named foo. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory.
A class path entry that contains * will not match class files. To match both classes and JAR files in a single directory foo, use either foo;foo/* or foo/*;foo. The order chosen determines whether the classes and resources in foo are loaded before JAR files in foo, or vice versa.
Subdirectories are not searched recursively. For example, foo/* looks for JAR files only in foo, not in foo/bar, foo/baz, etc.
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 wildcards is done early, prior to the invocation of a program's main method, rather than late, during the class-loading process itself. Each element of the input class path containing 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 foo contains a.jar, b.jar, and c.jar, then the class path foo/* is expanded into foo/a.jar;foo/b.jar;foo/c.jar, and that string would be the value of the system property java.class.path.
The CLASSPATH environment variable is not treated any differently from the -classpath (or -cp) command-line option. That is, wildcards are honored in all these cases. However, class path wildcards are not honored in the Class-Path jar-manifest header.
那么稍微翻译一下,假设lib是你的依赖
1. 如果a.jar, b.jar, c.jar都在lib下面,你可以 -cp lib/* Main 来把lib下面所有的jar放到cp下
2. 如果a.class, b.jar, c.jar都在lib下面,你可以 -cp lib:lib/* Main 来把lib下面所有的class文件和jar包放到cp下面
3. 如果lib/foo/a.jar,那么lib/*是不会获得a.jar的,因为通配符不会递归
4. 要注意的是,在classloader作用前,/*这种通配符就已经被扩展了;此外,不要让程序对jar包的加载顺序有要求。
have fun....
分享到:
相关推荐
关于java的classpath补充,详细说明如何配置classpath,如火热让javac正确编译运行java文件
主要介绍了Spring配置中的"classpath:"与"classpath*:"的区别,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
.classpath
classpath备份
Classpath Variable 解决办法
jdk的classpath路径和环境配置 jdk的classpath路径和环境配置
java classpath 理解 包括 1 在命令行查看classpath 2 在命令行设置classpath 3 classpath理解 4 命令行中直接使用classpath 很经典哦
classpath修改,相关jsp页面classpath修改
classpath 和path
自学如何使用框架的工具,项目框架添加classpath文件的
CLASSPATH="$CLASSPATH:""$jar" done windows : SETLOCAL ENABLEDELAYEDEXPANSION set LIB=xx set CLASSPATH=. FOR %%C IN (LIB\*.jar) DO set CLASSPATH=!CLASSPATH!;%%C echo %CLASSPATH%
本文详细介绍了path与classpath,以及它们之间的区别。
Android 4.4.4源码的.classpath文件,主要用于将Android 4.4.4源码的导入到eclipse工具中,提供给需要学习android源码的同学,也自己顺便记录一下,方便查找。
Java环境配置与设置JAVA_HOME_CLASSPATH_PATH的目的
详细讲解了java classpath 的详细过程,让你不在为配置java环境而烦恼,讲的非常好!word格式的!
本人在学习java的过程中深受classpath的折磨,为了让初学者少走弯路,我将这些经验总结了一番,总结了多种classpath的基本使用情况和常见的一些问题,以及解决方案和原理,供大家参考
用于处理PDF,或将PDF转换为jpg图片格式时用到的dll
Jamvm是一个c语言编写的开源的java虚拟机,它使用GNU classpath作为java类库