How to create an empty multi module Maven project?

后端 未结 8 409
孤独总比滥情好
孤独总比滥情好 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 
    
    0 讨论(0)
  • 2020-12-04 06:05

    Here is a screencast on how you could do it with Intellij Idea. First, start a new project (File -> New Project), choose 'Maven Module':

    enter image description here

    Type in a name, click next, don't change anything else in the following steps, click finish.

    Now in your pom.xml type <packaging> and enable auto-updates:

    enter image description here

    Type in modules:

    enter image description here

    Place your cursor at m1 and press Alt+Enter.

    enter image description here

    Module m1 will be automatically added to your project. Now you can do Alt+Enter for m2 and that's it.

    enter image description here

    You can also start by adding pom.xml for an existing module of your project: right click on it in the project tree, 'Add Framework Support...', choose 'Maven'. This will create a pom.xml.

    0 讨论(0)
提交回复
热议问题