DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Coding
  3. Java
  4. Working With Custom Maven Archetypes (Part 3)

Working With Custom Maven Archetypes (Part 3)

Adam Leggett user avatar by
Adam Leggett
·
Mar. 02, 10 · Interview
Like (0)
Save
Tweet
Share
32.98K Views

Join the DZone community and get the full member experience.

Join For Free

in part 1 and part 2 of this series i was able to demonstrate how you can create a custom archetype and release it to a maven repository. in this final part we’ll look at what you need to do to integrate it into your development process. this will involve the following steps:

  • uploading the archetype and its associated metadata to a maven repository manager .
  • configuring an ide to use the archetype.
  • generating a skeleton project from the archetype.

step 1 – upload your archetype

in part 2 we covered releasing and deploying the archetype. for reasons of brevity i simply demonstrated deploying a release to the local file system, but if we wish to share our archetype we must deploy it to a remote repository that can be accessed by other developers. a remote maven repository, in its simplest form, can be served up using a http server such as apache or nginx . however, these days i would recommend that you use a maven repository manager (mrm) instead, as these tools are purpose-built for serving (and deploying) maven artefacts. there are basically three options for your mrm – nexus , artifactory or archiva . a features matrix comparision is available here . all are available in open source flavours and both nexus and artifactory in particular are great tools. however, currently artifactory is the only one that supports a cloud-based service option which, as you might expect, integrates very well with our hosted continuous integration service . this allows you to provision yourself a fully-fledged mrm in very short order.

so, how do we add our archetype to the repository? this is a simple process using the built in artifact deployer of artifactory which allows you to upload a file and supply its maven gav co-ordinates.

artifactory deployer

next, we need to add some additional metadata about our archetype in the form of a ‘catalog’:

<?xml version="1.0" encoding="utf-8"?>
<archetype-catalog>
<archetypes>
<archetype>
<groupid>com.mikeci</groupid>
<artifactid>mikeci-archetype-springmvc-webapp</artifactid>
<version>0.1.4</version>
<repository>http://mikeci.artifactoryonline.com/mikeci/libs-releases</repository>
<description>mike ci archetype for creating a spring-mvc web application.</description>
</archetype>
</archetypes>
</archetype-catalog>

this file should ideally be placed into an appropriate folder of a maven repository and it contains information about all of the archetypes that live within the repository. we can simply add this file to our ‘libs-releases’ repository using artifactory’s rest api:

curl -u username:password -f -d @archetype-catalog.xml -x put "http://mikeci.artifactoryonline.com/mikeci/libs-releases/archetype-catalog.xml"

step 2 – configure your ide

now that our archetype is deployed remotely, we can start to use it from within our ide – in my case – eclipse. to get good maven integration inside eclipse, you really should be using the latest release (0.10.0) of m2eclipse . once m2eclipse is installed, it provides a handy feature that allows you to add and remove archetype catalogs. you will need to add your deployed archetypes catalog to the list of catalogs accessible from within m2eclipse. this ensures that you can access your custom archetypes when you run the create a maven project wizard in eclipse as we will see shortly.

choose the menu item, windows>preferences, to open the preferences dialog and drill down to the maven>archetypes preferences, as shown.


m2eclipse archetype prefs

click add remote catalog to bring up the remote archetype catalog dialog. in the catalog file text box, enter the path to your remote catalog file and in the description text box, enter a name for your catalog:

m2eclipse remote catalog

step 3 – generate your project

you should now be ready to generate a skeleton maven project inside eclipse. choose the menu item, file>new>other, to open the select a wizard dialog. from the scrollbox, select maven project and then click next. follow the wizard to configure your project location. eventually, the wizard allows you to select the archetype to generate your maven project. from the catalog drop-down list, select your custom catalog. then locate and select your archetype :

m2eclipse select archetype

click next and enter the gav values for your new project. et voila – you should have just created a skeleton project based upon your custom archetype using a slick ide wizard.

pretty impressive, don’t you think?

from http://blogs.mikeci.com

Archetype (information science) Apache Maven

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Steel Threads Are a Technique That Will Make You a Better Engineer
  • Tracking Software Architecture Decisions
  • Building a RESTful API With AWS Lambda and Express
  • Fargate vs. Lambda: The Battle of the Future

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: