I'm developing a modular web-app where I'm using maven. The skeleton of my application is the following:
The skeleton of my application with the share-services module
Now I want to import some classes of Service-App1 within Service-App2 but without the Service-App1 dependencies( like Module-App1, Util-App1 and the external dependencies).
Summarazing, since in the App2 I have a composite persistence unit Composite Persistence Unit and I want to share some business logic between applications. For example if in App1 I have a spring service like this:
public interface ContractService {
void processSomethings();
}
@Service
public class ContractServiceImpl implements ContractService {
public void processSomethings(){
//Manage some share entities
}
}
I would want use the method
processSomethings()
also in App1 How can I realize this?
You need to create a project (jar output) that contains just the classes that are shared between the two consumers. This may seem like an overhead, but it leads to clean well-organised code. If you can't do this, it is an indication that you have a confused dependency hierarchy. I do this regularly to implement web service clients and services, with a shared jar that contains the classes in common (i.e. the client should know nothing about DAO classes, but does need to know the signature of the web service operations. It also needs to have access to the POJO classes that define the data and message structure).
Also, do you need the hamcrest dependency at runtime? My experience is that it can usually have its scope set to test, so it never turns up in your compiled artifacts.
I'm not a convert to parent poms, and certainly would not consider the two-level parent pom structure you show. My objections are:
I'd like to hear reasoned argument on this topic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With