File. jar command console - client server program

Asked

Viewed 64 times

-2

I have developed a client server program, in which I have two Mains:

  • one to run the server
  • other to run several customers

To extract the file . jar from ecplise I export runnable Jar File.

I can run in the command console when I have only one main but two Mains? It’s just that when I export I have to clarify the main to run the program.

It makes no sense to join the two Mains since I only need to run the server once. I do need to run the client several times

  • It wouldn’t be the case to just run each jar in a different CMD window?

  • Hello rrr, I don’t know if I understand your need, but it seems to me you have two classes main, one for the client and one for the server within the same correct jar? Your problem is that you want to select which of the classes to run, is that it? If yes you can do this by placing the application jar in the classpath and specifying the class to be executed. See the first command of this response.

  • @Anthonyaccioly thanks for the interest. I already know how to solve the problem I will post the answer take a look

1 answer

1


Basically when there is a client-server type program the solution in creating a runnable jar with two Mains is to separate and create two jar’s apart. A jar with the server, and another jar with the client. This way it is possible to launch the server and several clients connected to that server because they connect via the same server socket.

  • 1

    This is the best solution in the long term, because in most cases the whole code is not reusable between client and server, it is not worth "distributing" a jar with the server code to a client and vice versa. From the point of view of evolution it is better to have separate modules. That being said, for a simple project there is nothing wrong with using something like the Maven-Assembly-plugin to generate two executable jars with diffraction Manifests for the same module.

  • yes exactly like this until the programs are divided

Browser other questions tagged

You are not signed in. Login or sign up in order to post.