How do you use Maven to share source code for two projects?

后端 未结 3 1690
陌清茗
陌清茗 2021-02-13 04:13

I have a large Java Web Application project using Maven and I need to start a new project that will share most of the same code (so I don\'t have to repeat work), but not all of

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-13 05:00

    Install the shared code, using your current packaging setting of jar:

    mvn install
    

    Then, you can create a dependency in the child pom.xml (the code that is not shared) from whatever repository you are installing to.

    This is good practice in general not only to avoid repeating work but also in case you want to change the implementation of the shared resources. You can change the logic in one place, install it to the repository, and other projects that depend on that code will use the new code the next time they are compiled.

提交回复
热议问题