Search code examples
javaeclipsebuildpath

Why order in java buildpath is matter?


In Eclipse (Project > Properties > Java Build Path) we have 2 tabs: for adding some libraries into buildpath, and for organizing their order. So, the question is why order in java buildpath is matter?


Solution

  • Because e.g. if you have A.class in two JARs then A.class may be different in these
    two JARs. The A.class from the JAR which is first on the path will be the one used.

    Suppose you build a library mylib, and you have two versions of it: mylib-1.0.jar
    and mylib-1.1.jar. Suppose somebody else uses your library and puts in his Eclipse build
    path both JARs. Now, suppose you have a class in both versions of this library/JAR called
    com.mycompany.mylib.DatabaseManager. There may be differences between
    DatabaseManager from 1.0 and the one from 1.1. So which one of the two
    DatabaseManager classes should Eclipse pick up in this case? Answer:
    the one from the jar which stands first on your build path.