简体   繁体   中英

Will JVM only pick up .jar files?

When I give the -classpath argument to java to start will it pick up only files which have .jar extensions or will it attempt to look into other files in -classpath path as well?

Meaning if I specify -classpath to be /mypath which contains

/mypath/IAmANormalJar.jar
/mypath/IAmAJarWithoutExtension

where IAmAJarWithoutExtension is an actual jar file but without the .jar extension. Will only /mypath/IAmANormalJar.jar be loaded by JVM or will /mypath/IAmAJarWithoutExtension be loaded as well?

http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/classpath.html

Classpath entries that are neither directories nor archives (.zip or .jar files) nor * are ignored.

The wildcard symbol explained:

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. Files will be considered regardless of whether or not they are hidden (that is, have names beginning with '.').

Java classpath requires jar to be completed specified with extension. Without the extension Java treats that as a directory to which there are class files present to be added to the Java classpath. The Wikipedia article on the Java classpath provides some good information in this regard:

https://en.wikipedia.org/wiki/Classpath_(Java)

It will only pick up files with the extension .class, .jar or .zip. One trick I used to use when I wanted to flip between two jars for testing would be to add another extension to the file I wanted to be "out". If the version I wanted to test was mylib.jar, I would modify the old one as mylib.jar.old and they could co-exist in the directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM