Adding an artifact to a local maven repository
In this tutorial you will learn how to add java and maven to your environment variables and add an artifact to your local repository in maven. This will help you to use external or private jars into your maven projectAdd maven and java to your environment variables
1. Install JDK from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2. Put JDK as an environment variable, look at the picture to see how can you do it. You need to create as a system variable.
3. Download and unzip maven. You can download from https://maven.apache.org/download.cgi
4. Create a directory called Apache in your C disc inside the program files directory.
5. Inside the Apache directory copy and paste the unzipped maven directory
6. Go to this equipment -> right click -> properties -> change configuration -> advance options -> environment variables
7. Create a new environment variable for maven like the image below in system variable. In my case the value was C:\Program Files\Apache\apache-maven-3.5.4
8. Add Maven and JDK variable to path variable like de image bellow. The value should be …;%JAVA_HOME%\bin;%MAVEN_HOME%\bin;…
9. Check the java variable by typing java -version
see the image below
10. Check the maven variable by typing maven –version
see the imagen below
You don’t need to create a repository explicity
Now let’s add the artifact
In my case I installed the Oracle JDBC which is important to develop a Spring web application by using a oracle data base as a repository. I downloaded from http://www.oracle.com/technetwork/database/application-development/jdbc/overview/quickstart-4308895.htmlType de following command
mvn install:install-file -Dfile=C:\Users\YourUser\Downloads\ojdbc8.jar -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar
Set the exactly address where you saved your artifact in front of -Dfile
Set the group id in front of -DgroupId
Set the artifact name or id in front of -DartifactId
Set version of your artifact in front of -Dversion
Set the type of toy artifact in front of -Dapackaging
More information https://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/
See the image below
Now you will to call your artifact in your pom.xml like this
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>
Be sure to set the exactly groupId, artifactId and version you set when you executed the maven install command.
Don’t forget to update your project after you set the dependency. In eclipse is right click on the project -> maven -> update project and ok
No hay comentarios:
Publicar un comentario