Search code examples
javajvmloadclasspath

How Java class are loaded from the same directory?


How a java application launched with the classpath: "lib/*" will choose witch class to load if the lib directory contains several JAR with the same class? The comportment will be the same every time? With different servers?


Solution

  • From the documentation:

    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.