Home > Back-end >  How to properly "export" an entity from one maven project to another?
How to properly "export" an entity from one maven project to another?

Time:11-29

I have a project with a regular structure.

project_a/
├─ src/
│  ├─ main/
│  │  ├─ java/
│  │  │  ├─ com/
│  │  │  │  ├─ myproject/
│  │  │  │  │  ├─ model/
│  │  │  │  │  ├─ Application.java
├─ pom.xml

The com.myproject.model package contains a large number of entity classes.

I need to create a new maven project that will use these entities.

project_a/
├─ project_b/
│  ├─ ...
│  ├─ pom.xml
├─ ....
├─ pom.xml

What is the best way to do this? From my ideas, this is to take the entity into a separate module (in general, to make a modular project).

And can I just import the com.myproject.model package into project_b as if it were a projcet_b package. What are the consequences of this?

CodePudding user response:

To achieve that one of the way is to make the entity into a separate maven module. If you are developing locally when you run the command mvn clean install it will generare the snapshot in the .m2 repository. If not , you can use tools like artifactory to store your dependencies somewhere and pull them when needed, but much more effort is needed in this case.

Another way could also be to import the JAR of the entity in your project.

Hope this helps.

  • Related