Maven uses the idea of Repositories to handle dependencies. But what if the dependency isn't present in any remote repositories or the central repository? Maven uses the idea of External Dependency to give a solution for such a scenario.
For example, let's make the following changes to the project we built in the 'Creating Java Project' chapter.
To the src folder, add the lib folder.
Any jar can be placed in the lib folder. We used the ldapjdk.jar package, which is an LDAP assistance library.
Our project's structure should now look like this:
This is a common scenario when you have your library exclusive to the project and contains jars that may not be available in any repository for Maven to download from. If your code uses this library with Maven, the build will fail since Maven cannot download or refer to it during the compilation phase.
To deal with the scenario, add this external dependency to maven pom.xml as shown below.
In the aforementioned example, the second dependent element under dependencies clarifies the following crucial facts concerning External Dependency.
External dependencies (the location of the library jar) can be defined in the same way as other dependencies in pom.xml.
The groupId must be the same as the library's name.
The artifactId must be the same as the library's name.
Set the scope to system.
Set the system path to the project's location.
I hope you now have a better understanding of external dependencies and will be able to declare them in your Maven project.