Ir al contenido principal

Using Maven just for dependency management

For quite some time now I've had the intention to learn how to use Maven and especially how to use it to manage the dependencies for my projects without having to do anything special. I share with you what is necessary to achieve the same thing in your own projects.

First we need to have Maven installed.  You can download Maven from Here so you can execute it from the console or you can install the plugin for eclipse, just search for a plugin called "m2e - Maven Integration for Eclipse" in eclipse and install it.

The next thing to do is to replace the commented code in the "pom.xml" by following the steps below:
  • The grouping.id, can be for example the package name of the project in which you use the pom for example com.domain.project.
  • The artifact-id, might be something like domain-project (for domain-project.jar) or project (for project.jar) without taking into account the version.  So for commons-logging-1.1.1.jar for example the artifact id would be commons-logging.
  • Replace the string "libs" inside <libraries.folder>libs</libraries.folder> with the path in which you want the jars to be stored. For a website project developed using Eclipse it could be for example something like "WebContent/WEB-INF/lib".
  • Locate the piece of xml below and add the dependencies you want to be automatically managed by Maven.  In this Url you can search for the dependencies you wish to add.
<!-- Your dependencies -->
<!--dependency>
<groupId>group id</groupId>
<artifactId>artifact id</artifactId>
<version>the version number!</version>
</dependency-->
  • And finally add the repositories you need, generally you do not need to configure any additional repositories, however, there are times in which the jar that we are looking for is not in a general repository so we might get a problem that says "Could not resolve dependencies for project" and "Could not find artifact", in this case we must find out which is the repository where the jar is located and then add the repositories where the following piece of xml is located.
<!-- Your repositories -->
<!--repository>
<id>Repo ID</id>
<name>Repo Name</name>
<url>http://repourl</url>
</repository-->

The file “pom.xml” is designed so that nothing else is necessary to be added in order to run it, just type “mvn” from within the path where the “pom.xml” is located and then press enter or from within Eclipse right click the pom, “Run As”, “Maven Build” and then clicking the “Run” button will start the execution.  At this point Maven will create a folder, if it doesn't exist already, and it will download all the jars that you added and their respective dependencies.

Here is the complete code:

Well, I hope this post has been helpful.

Comentarios

Entradas populares de este blog

How to copy files from and to a running Docker container

Sometimes you want to copy files to or from a container that doesn’t have a volume previously created, in this quick tips episode, you will learn how. Above is the vid and below you will find some useful notes. 1. Pre-reqs Have Docker installed 2. Start a Docker container For this video I will be using a Jenkins image as an example, so let’s first download it by using docker pull docker pull jenkins/jenkins:lts

How to create an AEM component using Reactjs

In this tutorial, I will show how to use use Adobe's archetype to create an AEM application with React.js support and also how to add a new React.js component so that it can be added into a page, above is the vid and below you will find some useful notes. In the second part we will see how to configure the Sling Model for the AEM React component. 1. Pre-reqs Have access to an Adobe Experience Manager instance. You will need aem 6.4 Service Pack 2 or newer. Have Maven installed, understand how it works and also understand how to use Adobe's archetype, you can watch my video about maven here: Creating an AEM application using Maven and Adobe's archetype 2.

House price prediction 3/4: What is One Hot Encoding

A series about creating a model using Python and Tensorflow and then importing the model and making predictions using Javascript in a Vue.js application, above is the vid and below you will find some useful notes. Here, in part 3 of this series, I will show what is and how does one hot encoding works. In the first post, called House price prediction 1/4: Using Keras/Tensorflow and python , I talked about how to create a model in python, pre-process a dataset I've already created, train a model, post-process, predict, and finally about creating different files for sharing some information about the data for use on the second part. Then in part 2, called House price prediction 2/4: Using Tensorflow.js, Vue.js and Javascript , I took the model, the data for pre and post processing and after loading everything we were finally able to predict