Table of contents
1.
Introduction
2.
Maven's External Dependencies
3.
Addition of Maven's External Dependencies
4.
Frequently Asked Questions
4.1.
How to use Maven's external dependencies?
4.2.
What does the SNAPSHOT keyword signify?
4.3.
How to deploy the JAR file in the remote repository?
4.4.
Why use external dependencies?
4.5.
Why is it advised to keep the external dependencies in Maven’s local repository rather than the remote repository?
5.
Conclusion
Last Updated: Mar 27, 2024

What do you mean by Maven's External Dependencies?

Author Vanshika
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Maven is a robust build management tool with dependency management as its main feature. Managing dependencies in a multi-module project is complex. Hence, Maven plays an essential role in addressing them. For more information about Maven, you must read.

In this article, you will learn about Maven's external dependencies and how to use them in our project.

What do you mean by Maven's external dependencies?

Maven's External Dependencies

In the article, various scopes of Maven dependency. We discussed the multiple scopes of Maven dependency – compile, provided, test, runtime, import, and system. Maven is the dependency handler. Now you might be thinking, what are external dependencies? Before understanding the answer to this question, let us first discuss some terms –

  • Local Maven Repository – It is a folder located on your local computer. This folder is created when you run any Maven command for the first time. It helps in collecting all the project dependencies in one place.
     
  • Central Maven Repository – It is a repository containing many library JARs and requires no configuration. The Maven community manages it. This repository can be found and used through Maven’s website.
     
  • Remote Maven Repository – This repository comes into the picture when the required library JARs are not found even in the central maven repository. It is a custom repository containing the required project’s library JARs.
     

Returning to the question, you’ll relate to the terms mentioned above. The dependencies used when the required JARs are unavailable in the local, remote, and central Maven repositories are termed external dependencies. So, external dependencies are used when you cannot find the libraries required for your project in any of the three Maven repositories. Sqljdbc.jar or log4j are examples of Maven's external dependencies. Within the pom.xml file, Maven can configure external dependencies easily.

Addition of Maven's External Dependencies

We are considering the example of adding sqljdbc.jar external dependency in our Maven project. Here, we add sqljdbc.jar to the mavenproject created in Maven NetBeans (with the help of this article, you will also learn how to make any project in Maven).

  • Open your Maven project in which you want to add the external dependencies.
Project structure of Maven project

The project structure looks somewhat like this in the beginning.
 

  • Create a folder in your project’s root directory. Here, I’m creating a folder named libs (you can keep any). Steps for making a new folder - 
    • Right-click on the project → properties. Check the location of the project.
       
    • Go to that location and make a new folder (here, libs).
       
    • You will find that a folder named libs has been added to your project structure.
       
  • Download the sqljdbc.jar external dependency and add it to this newly created libs folder.
     
  • Now, add this new dependency in the pom.xml of your project using the code below -
<dependencies>
        <dependency>
            <groupId>sqljdbc</groupId>
            <artifactId>sqljdbc</artifactId>
            <scope>system</scope>
            <version>1.0</version>
            <systemPath>${project.basedir}\libs\sqljdbc.jar</systemPath>
        </dependency>
</dependencies>


The format for adding dependencies remains the same. You can refer to this to learn more about dependencies and their scope.

  • groupId must be the name of the jar file.
     
  • artifactId must also be the name of the jar file.
     
  • scope specifies the stage up to which you can include a dependency.
     
  • systemPath specifies the relative path of the jar file to the project location.
     

Using the steps shown above, you can add as many external dependencies as possible based on the project’s demand.

Frequently Asked Questions

How to use Maven's external dependencies?

The external dependencies are added in the pom.xml files under the <dependencies> and further <dependency> section based on the needs of your project.

What does the SNAPSHOT keyword signify?

The SNAPSHOT keyword used while creating a project signifies that the project is still under development, which means the code can change or be unchanging.

How to deploy the JAR file in the remote repository?

Using pom.xml and settings.xml, you can deploy jars to external repositories by specifying the repository URL and authentication information.

Why use external dependencies?

You need to use external dependencies when any particular dependency is unavailable in the Maven remote, local and central repositories.

Why is it advised to keep the external dependencies in Maven’s local repository rather than the remote repository?

Local repositories consume less space, are easily accessible, and there is no need to take care of versioning for jars; therefore, it is advised to keep the external dependencies in the local repository.

Conclusion

In this article, you learned about Maven's external dependencies, their needs, and how to use them in our Maven project. At this point, you might have learned a lot about Maven. If not, then read the following articles:

If you’re thorough with Maven, check out Maven Interview Questions.

For leading and upskilling yourself in the right direction, check out the guided paths by various industry experts. Here you will learn Data Structures and AlgorithmsCompetitive ProgrammingSystem Design, and many more courses on our fully-fledged platform Coding Ninjas Studio. After availing of the benefits from our courses, you may check out your competency by referring to the mock test and problems available. Take a look at the interview experiences and interview bundle for placement preparations.

Happy Learning :)

Live masterclass