Skip to content
Alejandro Medrano edited this page Mar 18, 2018 · 7 revisions

Table of Contents

Creating a new project based on an existing Archetype using Eclipse

When creating a new project it is always a good idea to start with a template, this way the start of the actual developing of the project is not in square 1. Maven realizes this, and one of the countless functionalities it offers is precisely this, a mechanism to provide templates for new projects, these templates are called Archetypes.

The Maven plugin for ecplise also give a fast and easy way to obtain these archetypes and start projects in a snap. To create a new project from an archetype click on File->New->Project... just as you'll do to create any other project.

The next step is to select a Maven project, because archetypes are Maven projects, and model new Maven projects.

The Maven project wizzard is simple, just select where you want lo locate the new project (by default it will be located in a new file in the workspace). Before clicking next make sure create a simple project is NOT selected, this will skip the Archetype selection, infact it will automatically select a simple Java Maven project Archetype by default. As we wan to use another archetype click next.

The Archetype catalog is a simple interface displaying all the listed and installed Archetypes, but this does not mean that it shows all of them...

To add a Archetype to this list click on "add archetype". The next step is straight forward, fill in the information you are given about the archetype (groupID, artifactID and the version) Maven will look up this Archetype as it does for any other artifact, by looking up the remote repositories listed in your settings XML. This is why the repository URL parameter is not mandatory, as long as you have the universaal nexus repository listed in your settings (which you will if you followed the maven configuration procedure).

This last step will only be necessary once per new archetype used. This is because adding an archetype will install the artifact in the local repository, and therefore then it will be listed in the archetype catalog.

The archetype catalog has a filtering mechanism which is pretty useful to quickly find the artifact you're looking for.

Once the archetype is selected click next, and fill in the last required information. This is the groupID, artifactID, version that your new project should have. Also there is the posibillity to specify the main package's name and other archetype properties. Click on finish and you are ready to go.

Creating a new project based on an existing Archetype using Maven

The same can be achieved through maven commands. First download the archetype to your local repository, and update local catalog:

  mvn dependency:get archetype:crawl -DartifactId=... -DgroupId=... -Dversion=... 

Completing groupID, artifactID and the version for the archetype you want to use. If the previous command can not locate the archetype add the following parameter:

  -DremoteRepositories=uaal::default::http://depot.universaal.org/maven-repo/releases/,uaal-snapshot::default::http://depot.universaal.org/maven-repo/snapshots/,uaal-p1::default::http://nexus.lst.tfo.upm.es/content/groups/public/

Then every time you need to generate a proyect just instantiate it with:

  mvn archetype:generate -DarchetypeArtifactId=... -DarchetypeGroupId=... -DarchetypeVersion=...

Completing groupID, artifactID and the version for the archetype you want to use. If you preffer an interactive selector, remove the -D parameters.

available Archetypes in uAAL

GroupID ArtifactID Description
org.universAAL.samples karaf.feature-archetype template for Karaf Feature provision
org.universAAL.samples module.generic-archetype template for container independent module (same style as ontologies)
org.universAAL.samples module.osgi-archetype template for OSGi module
org.universAAL.runners pax.runner-archetype template for OSGi Pax runner Felix execution
org.universAAL.ui.gui.swing defaultBasedLAF-archetype Create a look and feel for the Swing GUI handler based on the default one

Creating Archetypes for others to use

This section is based on the information found on the official archetype plugin web page.

To create and publish your archetype (template) follow these simple steps:

1. create a maven project (with it's POM). This project will be the actual template so put in everything you wish to include in the archetype (also every thing you wish to be in the new project's POM file).

2. open a terminal go to the projects main directory and execute

 mvn archetype:create-from-project

3. this will create the archetype project in the directory target/generated-sources/archetype/. To obtain/configure the groupID, ArtifactID and/or version edit the archetype's POM file (there are also some advanced things that can be done to the archetype's POM)

4. To share the archetype, deploy it in the nexus repository by running the command:

 mvn deploy

You may need to configure the deploying repository (<distributionmanagement></distributionmanagement> section of the archetype's POM).

5. So everyone is aware of your archetype, and it has the chance to be used, update the list of available archetypes.