How to create an empty multi module Maven project?

后端 未结 8 441
孤独总比滥情好
孤独总比滥情好 2020-12-04 05:19

Right now I usually find a pom.xml file on the web that has a pom packaging and copy and paste it to create my parent project. Then I used to run <

8条回答
  •  眼角桃花
    2020-12-04 06:04

    Consider a parent project bookmarks and 3 sub modules rest, security and model, referring to Spring docs. It doesn't have the dependencies as in the Spring doc, just the basic setup from multi-module point of view.

    To create a parent maven project in non-interactive mode/ batch mode

    mvn archetype:generate \
    -DarchetypeGroupId=org.codehaus.mojo.archetypes \
    -DarchetypeArtifactId=pom-root \
    -DarchetypeVersion=RELEASE \
    -DgroupId=bookmarks \
    -DartifactId=bookmarks \
    -Dversion=0.0.1-SNAPSHOT \
    -DinteractiveMode=false
    

    To create sub modules in non interactive mode/ batch mode.

    cd into your newly created root dir. Referring to answer by @Chris.H

    -Dpackage is the package structure. Here it is bookmarks. If not specified then it will consider the artifactId as default package

    mvn archetype:generate \
    -DarchetypeGroupId=org.apache.maven.archetypes \
    -DarchetypeArtifactId=maven-archetype-quickstart \
    -DarchetypeVersion=RELEASE \
    -DgroupId=model \
    -DartifactId=model \
    -Dversion=0.0.1-SNAPSHOT \
    -Dpackage=bookmarks \
    -DinteractiveMode=false 
    

    To create a new module in eclipse goto File->new->other->maven->maven module, this shows up immediately in eclipse workspace package explorer.

    Or from cli, cd inside parent folder, here bookmarks and run the following, it will create the project and then you have to import into eclipse as a maven project, or can work from parent, here bookmarks project

    mvn archetype:generate \
    -DarchetypeGroupId=org.apache.maven.archetypes \
    -DarchetypeArtifactId=maven-archetype-quickstart \
    -DarchetypeVersion=RELEASE \
    -DgroupId=security \
    -DartifactId=security \
    -Dversion=0.0.1-SNAPSHOT \
    -Dpackage=bookmarks \
    -DinteractiveMode=false 
    

提交回复
热议问题