Class Path Wild Cards

https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html

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 .jar or .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 mydir are loaded before JAR files in mydir or 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 mydir contains 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 CLASSPATH environment variable is not treated any differently from the -classpath or -cp options. Wild cards are honored in all of these cases. However, class path wild cards are not honored in the Class-Path jar-manifest header.


翻译总结:
  • * 表示只匹配到JAR文件, 不包含子目录, 不包含Classes
  • 目录 表示要加载的Classes或是Resources
  • 顺序问题: 不翻译了

猜你喜欢

转载自fjjiaboming.iteye.com/blog/2243907