I have three pools(apps) that transform data sequentially and communicate with each other by socket (or get, post - nevermind). And I have servlets, that accept data and transfer data to one of the starting pool. How can I run it all in one container (tomcat, wildfly)? Make 3 jar, 1 war artifact or something else? that should be written in the pom.xml?
Well, communication between the modules is important:
If you are content with them communicating by direct, local API invocation, you must necessarily build one single war containing the three modules (typically one JAR for each module).
But if you want a distributed application, the communication should be remote (either through TCP sockets, RMI, HTTP, ReST, etc). In this way, you may build one assembly for each module: It should be a WAR if the module contains servlets/JSPs, or a JAR if it does not.
In Maven, this translates to:
packaging=pom
, and one <module>
declaration for each module.package=jar
or war
(depending on the above decission).It is also important to deploy and start each module depending on its type (as commented by @Carlitos Way):
Each one of the non-web modules should have a main class which will be in charge of receiving the required arguments from the command line (at least the port number) and start the listening class - whatever it is.
package module.cmd;
public class MyMainClass
{
public static void main(String[] arguments)
{
int port=Integer.parseInt(argument[0]);
new MyListener(port).start();
}
}
To run it, it would be enough to execute:
mvn exec:java -Dexec.mainClass="module.cmd.MyMainClass" -Dexec.args="8001"