简体   繁体   中英

How can I make an existing maven project as a part of multi module maven project?

My goal is to turn an existing maven project (char-counter) into a module of my multi-module maven project. How can I do this? I use Eclipse 4.16.0.

Here is the structure of my projects. 在此处输入图片说明

You can include the sub-modules inside your parent maven project in following way.

Inside your multi-module-project pom.xml

<modules>
    <module>char-counter</module>
</modules>

See here: Maven Multiple module

Assuming that you want to convert your char-counter project to multi-module-project.

You need to have following in your multi-module-project pom.

<groupId>com.parent</groupId>
 <artifactId>multi-module-project</artifactId>
 <version>1.0.0-SNAPSHOT</version>
 <packaging>pom</packaging>

<modules>
 <module>Anagram<module>
 <module>Calculator<module>
</modules

And then in Anagram project's pom :

<parent>
        <groupId>com.parent</groupId>
        <artifactId>multi-module-project</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

     <groupId>com.child</groupId>
     <artifactId>Anagram</artifactId>
     <version>1.0.0-SNAPSHOT</version>
     <packaging>jar</packaging>

And in Calculator project's pom:

   <parent>
        <groupId>com.parent</groupId>
        <artifactId>multi-module-project</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

     <groupId>com.child</groupId>
     <artifactId>Calcultor</artifactId>
     <version>1.0.0-SNAPSHOT</version>
     <packaging>jar</packaging>

Also you need to add dependency of one module to other,in which you want to use the code from other module and then you need to deploy the artifact(module) which has dependency included in it and has starting point to run (like main).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM