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?
-
Why do you have 3 apps?? If those apps have different tasks between them, which component coordinate their work ? – Carlitos Way Jan 17 '17 at 18:37
-
I don't have any, I want to know how can I create one deployed project in the container with three jar ( or thousand) and one war (or many?) which will interact with each other as separate applications – kcc Jan 17 '17 at 18:44
-
Client -> doGet (servlet) -> central pool ------ via sockets ----> second pool (get information from DB) ------ via sockets ----> third pool ( do something with message). It's abstract task – kcc Jan 17 '17 at 18:49
-
create a war file that include your pools app as dependency jars ... However, you will only need the war file for the servlet part ... how do you plan to start (Technology) your sockets at your pools apps (this will affect your deployment) ?? – Carlitos Way Jan 17 '17 at 18:51
-
How I can create it with maven, deploy from 4 modules source code (three jar, one war), what's what I mean – kcc Jan 17 '17 at 18:56
-
https://maven.apache.org/plugins-archives/maven-archetype-plugin-1.0-alpha-7/examples/webapp.html ... and start filling your pom file – Carlitos Way Jan 17 '17 at 18:58
-
I know structure of the web application. But is it impossible to run .Jar with application that listening some port or container doesn't allow it – kcc Jan 17 '17 at 19:02
1 Answers
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:
- Create a parent project which contains all of the modules, with
packaging=pom
, and one<module>
declaration for each module. - Then, create a module project (within the parent) for each module, with
package=jar
orwar
(depending on the above decission). - Set the proper dependencies between them in case you need to expose their public APIs as the way to inter-communicate.
It is also important to deploy and start each module depending on its type (as commented by @Carlitos Way):
- WARs are necessarily deployed to a servlet container (Tomcat, for example).
- JARs can be started from the command-line with a shell script.
Start an application which listens to a port
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"

- 8,563
- 2
- 18
- 46
-
-
Yes, I doing exactly the same: - one pom, which includes
jar1 jar2 jar3 war1 -
How to start an application within a jar which listens to a port? Suppose you have a class with a `main` method which receives parameters and starts the listening socket. Then, you must just invoke [`mvn exec:exec`](http://www.mojohaus.org/exec-maven-plugin/usage.html) from the project directory. – Little Santi Jan 17 '17 at 19:30
-
Could you please provide me with the link to a similar project or a book or an article? I don't quite understand how to make it work. – kcc Jan 17 '17 at 19:38
-
-
Hum... I can't provide any references, but it's not that difficult. I've added the part about a command-line entry point that starts to listen to a port. – Little Santi Jan 18 '17 at 23:30