jmoyano jmoyano - 7 months ago 24
Java Question

Import package into other module of the same maven project

I've got a maven parent project that has two child modules (spring ws archetypes) each one is intend to be deployed in its own application server. One of the modules exposes a ws endpoint that is used by a ws client in the other module.
My problem is that i will have the java objects generated by jaxb and xsd in both modules, unless i find the way to share this set of classes without replicating it.
Is there any way to import an specific package from one module to the other? Is there other more appropriate way to deal with this problem?

  • create a ws-api maven module that only contains the api classes interfaces.
  • create a ws-impl that depends on the ws-api, because it implements it.
  • create the client module with the ws-api module as it's dependency, because it uses it.

Then you have the following structure, you can reuse the api clases and you have a clear api:

   +- ws-api
   +- ws-impl
   +- client

The module dependencies will be

+------------+       uses     +------------+
|   client   |    -------->   |   ws-api   |
+------------+                +------------+
                                    | implements
                              |  ws-impl   |

In this setup the jaxb objects have to be generated in the ws-api module.

For a detailed explanation of why to separate the api and implementation take a look at my blog