Wednesday, 9 October 2013

Create Custom Archetype and Deploy on Remote Artifactory

This post explains creating a maven archetype from already existing Maven project and deploying it on Remote Artifactory

If remote artifactory does not exists, it can be created by using jFrog



1. Creating Archetype

Go to Project Root directory from command prompt and type

mvn archetype:create-from-project

This will create a {project_root}/target/generated-sources/archtype folder.






2. Installing Archetype to local Repo

Go to {project_root}/target/generated-sources/archtype and type

mvn install



3. Installing Archetype to Remote Repo

Login to Remote Artifactory http://192.168.200.35:8080/artifactory/ with credentials as admin/password
Go to Deploy tag. In the Uploaded File field choose the
{project_root}/target/generated-sources/archtype/target/{archetype_name}.jar
and Click upload


Choose a valid Target Repository. For e.g. ext-release-local
In GroupId, ArtifactId, Version enter values from pom.xml present at
{project_root}/target/generated-sources/archtype/pom.xml

<groupId>com.nihilent.rest-webapp</groupId>
 <artifactId>rest-webapp-archetype</artifactId>
<version>0.1</version>
Click Deploy Artifact

4. Create a Catalog file and upload it with you archetype
Now this archetype is deployed on your artifact. We will need a catalog file to use this archetype.

Create archetype-catalog.xml
<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog>
       <archetypes>
          <archetype>
              <groupId>com.nihilent.rest-app</groupId>
              <artifactId>rest-webapp-archetype</artifactId>
              <version>0.1</version>
              <repository>http://192.168.200.35:8080/artifactory/ext-release-local</repository>
              <description>Nihilent Spring Based REST Webservice Project </description>
          </archetype>
       </archetypes>
</archetype-catalog>

Login to Remote Artifactory http://192.168.200.35:8080/artifactory/ with credentials as admin/password
Go to Artifacts and check the libs-release-local folder
if their is a file present at location <Artifactory_Path>artifactory/libs-release-local/archetype-catalog/archetype-catalog/1.0/

than download the file and add the below snippet in it in the archetypes section

If this file is not present than create a new file as given above and upload it from Deploy tab

Go to Deploy tag and choose the archetype-catalog.xml and click Upload. Choose a valid Target Repository. For e.g. Libs-release-localIn GroupId : archetype-catalog, ArtifactId : archetype-catalog, Version : 1.0 and upload it.

5. Configure Eclipse to use this catalog

Go to Window--> Preferences - >>maven --> Archetypes

Click Add Remote Catalog and in Catalog File mention the http://192.168.200.35:8080/artifactory/libs-release-local/archetype-catalog/archetype-catalog/1.0/archetype-catalog-1.0.xml or else you can choose Local Catalog and provide the path of the downloaded catalog xml file. 

In Decription enter Nihilent Archetype

Click Verify to verify that some archetypes are present at this location.

6. Creating Project from custom Archetype

File->New->Project..->Maven Project->Next
       In Catalog Drop Down select Nihilent Archetype
       And select the required Archetype as shown below



Share the post