There is a web application that runs on tomcat . There is also another application, a console, run through the main method. Both the one and the second applications contain a DAO layer using Hibernate . The entities in both applications are the same, and adding a new one to one of the applications requires duplicating it on the second, which is not very convenient.

I would like to combine these two applications into one, so that they have a common entity package and a DAO layer, a common pool of hibernate connections. I am not sure that this is possible, as the Web application in my understanding works after the arrival of the Request on the Servlet .

Tell me, please, is such a scheme realizable?

PS

, That it is possible to use listener , it can be an output?

  • tomcatee? Then it seems you can put it on an ejb server to which you can connect with a client, both local and remote. In this ejb to make the methods that both clients need. They themselves put the java-ee tag, and look in this direction. ee for this and conceived. Just from DAO make this ejb. - Sergey

1 answer 1

Yes, listener is ok. Of course, it is often used to initialize a web application. But no one forbids a listener to create a thread or timers, which will then do something. It depends on what you want to do.

If the functionality that implements the console offer is started / used manually, then you can also look away: