Install Maven Archetype
Asked Answered
C

4

16

I have created a Maven archetype from an existing project. I have even installed the archetype in my local repository and used it to create a new project. Everything went perfect (incredible).

The thing is that I want to distribute this archetype so anybody can install it in his local machine or even deploy to a maven repo in order to use it. I was thinking about distributing the generated the artifact JAR, not the source of my project, and let people install it but it seems like it doesn't install as an archetype or at least it isn't recognized when I try to use it.

I used mvn install:install-file goal to do this.

Is this the best way to do this? Is it posible to distribute this JAR file in order to install it as an archetype? Is the JAR file missing something?

Thanks in advance.

Cupp answered 26/10, 2012 at 15:0 Comment(2)
mvn deploy doesn't work...?Mablemabry
Didn't try it. Is that what I'm supposed to do? Do I have to deploy the archetype on my local repository? The question I am trying to get answered are this: Can an archetype be distributed in a JAR file? Do Inhave to install or deploy it on a local repository?Cupp
S
26

Few clarifications here:

// installs the project to your local repository (jar, archetype, etc.)
mvn install
// AND updates archetype catalog
mvn install archetype:update-local-catalog
// calls plugin archetype goal crawl
mvn archetype:crawl

Crawl goes through Maven repo and CREATES catalog.

If you wish to use archetype interactively, you either need to call if with full coordinates or have it listed in the catalog.

// use local catalog
mvn archetype:generate -DarchetypeCatalog=local
// full coordinate set, my example
mvn archetype:generate -DarchetypeGroupId=pl.lafk -DarchetypeArtifactId=simple-testng-quickstart -DarchetypeVersion=1.0 -DgroupId=pl.lafk -DartifactId=sample-app

When you call mvn deploy you do all that install does plus push the package to remote repository - if you have it configured.

Link I used was Maven site for plugin: https://maven.apache.org/archetype/archetype-packaging/index.html

Additionally: mvn archetype:help

Suttles answered 10/4, 2016 at 22:14 Comment(0)
H
5

Hi it is a late response, but I had the same problem that I didn't find a clear instruction how to share an archetype. So I hope that the following will help someone who struggles as lot as I did:

  • Develop your archetype: Either alone or with mvn archetype:create-from-project. There are enough instructions in the internet which explain how to do that.
  • Enter the distribution-management element in your pom.xml where the nexus-repository you want to publish/share your archetype must be defined. The link with the maven/settings.xml for the connection properties and so on is made with the id element and not with the url element.
  • call "mvn clean install" with all options you want to install the archetype in your local maven repository
  • call "mvn deploy" and maven will do the rest and update your remote archetype-catalog.xml by itself!
  • to test that the archetype is really recognized call "mvn archetype:generate -Dfilter=[your archetype artifactid]" and it should be in the list.
Hernadez answered 5/10, 2017 at 8:18 Comment(0)
B
2

For those looking for more recent info: The way to use an archetype catalog in a custom repository for the current version of the plugin (see date of this comment), is defining in your setting (~.m2/setting.xml in Mac) the repository with id "archetype":

<repository>
    <id>archetype</id>
    <name>archetype_company_repo</name>
    <url>http://your.company.com/nexus/content/repositories/releases/</url>
</repository>
Bibber answered 2/8, 2018 at 23:40 Comment(0)
M
0

Maven archetypes are artifacts just like any other project build artifact. You deploy them to your repository with the Maven deploy command.

See Guide to Creating Archetypes, Maven by Example and Maven: The Complete Reference for more on these topics.

Mablemabry answered 26/10, 2012 at 21:15 Comment(2)
Aside from kinda skimpy in that regard first link, other links are dead.Suttles
Well...it has been almost 4 years. Best of luck!Mablemabry

© 2022 - 2024 — McMap. All rights reserved.