Russell Milburn
Russell Milburn

Reputation: 109

Running a Java Application to run on a tomcat sever

I have created a Socket Server application that will accept Client connections from other computers on the local network. This is application is run from a public static void main method. and is a very standard java application.

I have also created a web service that runs on tomcat, it also uses java. The web service will http post accept request from any internet connected device.

Once the web service receives a request I would like it to send instructions through the socket server and send some data to the client connected.

I would like to run the socket server applicaiton within the web service so that the web service has access to the socket server without having to connect as a client.

What is the best way to run a standard java app so that the tomcat server will start the application when it starts up? should i run it as a servlet or is there a better way to have the web service access the socket

Upvotes: 2

Views: 1607

Answers (1)

kolossus
kolossus

Reputation: 20691

An application opening its own server socket within a proper application server is pointless and possibly counter productive IMO.

Think about it: Tomcat is probably running on port 8080. Your application is hypothetically going to be running on port 9080. What port do you think clients will need to connect to, to consume your service? And if you answered that correctly, what service/benefit are you then expecting Tomcat to provide you, if your clients are in fact, not going to interact with tomcat at all?

You don't need a (full) application server to run your own personal server. You have the option of:

  1. a Java web service without a web application server, which lets you deploy a full JAX-WS webservice within the vanilla JSE, no application server required

  2. Using the jdk's embedded HTTP server to process your requests

  3. Deploying your standalone application as a windows (or other OS) service

Upvotes: 2

Related Questions