Create Maven Local Repository, Upload your own artifact & download jar from local mirror with Artifactory and Nexus OSS

Maven is nothing but a software project management tool as well as build tool unlike Ant (Wheres ant is only a build tool).

From maven official website
Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting, and documentation from a central piece of information.
Well, Now we go to direct how to configure a local repo for maven. Here I used  JFrog Artifactory for repo manager but you can do it with other software like Nexus OSS and so on. I'll tell you both how to install. Download zip format  [JFrog Artifactory] from here.After download extracts the zip file and it contains everything that you need. It also includes the tomcat. It looks more or less something like that,

Now we are going to deploy webapps artifactory.war and access.war which is in webapps folder. Remember that we need to install java-8(at least ) in our system too. So goto webapps folder and copy those war file and paste it in /tomcat/webapps folder. Now start the tomcat by

  1. Open commands prompt and go to your working directory.
  2. Go to tomcat/bin folder and run startup.bat file.
After tomcat is in running state it will auto deploy your webapps and necessary db information it needs to create (usually derby db in local filesystem).
Remember that, Artifactory is not free. But you can get a one-month trial license by signing up.
After deployment open browser and hit the url http://localhost:8081/artifactory
Default "username/password" for admin is "admin/password".
After login you can see the dashboard. Activating your product by trial license or full license you can access all the menu.
Now create a new local maven repo from menu Admin->Repositories(local)-> New
In my case I create a local repo named "mu_maven". Well we done all from server end. 
Back to client end and go to maven home open settings.xml

 <profile>  
    <id>ce</id>  
    <repositories>  
     <repository>  
      <id>ce</id>  
      <name>Repository for JDK 1.8 builds</name>  
      <url>http://localhost:8081/artifactory/mu_maven</url>  
      <layout>default</layout>  
      <snapshotPolicy>always</snapshotPolicy>  
     </repository>  
    </repositories>  
 </profile>  
and add a server credential in <servers> section

 <server>   
   <id>central</id>   
   <username>admin</username>   
   <password>password</password>   
  </server>  
 <server>   
   <id>snapshots</id>   
   <username>admin</username>   
   <password>password</password>   
  </server>  
Remember the <id> here I kept "central" and we gonna use it in POM, when we build the project.

Now create a new maven project in Netbeans and open POM file.Add the distribution management to it.

 <distributionManagement>  
     <repository>  
       <id>central</id>  
       <name>mu_releases</name>  
       <url>http://localhost:8081/artifactory/mu_maven</url>  
     </repository>  
     <snapshotRepository>  
       <id>snapshots</id>  
       <name>mu_snapshots</name>  
       <url>http://localhost:8081/artifactory/mu_maven</url>  
     </snapshotRepository>  
   </distributionManagement>  
Url should be our created local repo location. In repository tag we have an element named <id>. Here I kept "central" which is equal to server <id>. This name should be equal.
Ok, then go to your project directory, open command prompt and run the command "mvn clean package". If successfully build then run "mvn deploy". This command will deploy your jar to directly our created repo (mu_maven). To browse the jar hit the url http://localhost:8081/artifactory/mu_maven/ and see your jar. If you want that you want to use your local repo instead of central maven then you should add a mirror in settings.xml
Add this piece of code.

 <mirror>  
    <id>mirrorId</id>  
    <mirrorOf>*</mirrorOf>  
    <name>Human Readable Name for this Mirror</name>  
    <url>http://localhost:8081/artifactory/mu_maven</url>  
 </mirror>  
This will search jar in local repo [e.g that you include in your porject POM].

How to setup NEXUS OSS:
Download nexus oss from the official website. Here I downloaded the version 2.14.
Well after unzipping see this folder structure. Remember nexus run on a jetty server.


Before install and start nexus I changed the port for other port conflict. Go to conf folder and open nexus.properties file. Changed application-port:9081 and that's it. Now Go to bin folder and open command prompt in administrator mode. Type the command below,

  1. nexus install
  2. nexus start
This command will install and start nexus as a windows service. You can access your repo by hitting the url http://localhost:9081/nexus/. You can login your repo by default username/password: admin/admin123. To stop the service use the command nexus stop.

That's all for setting up the local maven repo.
Cheers.

Comments

Popular posts from this blog

UUID to BigInteger conversion and BigInteger to UUID conversion

ActiveMQ message producer and consumer with durable subscriber example