-2

I would like your tipps about implemening a command line interface to interact with a running java application.

Example:

The Java Application is a webserver and a cli-client should interact with it:

1 ) Start server application: java -jar webserver.jar

2) Get status of the running application: java -jar webserver.jar --status or other commands like: java -jar webserver.jar --add-user Paule --password 1234 so adding an entry in a hashmap in the running application.

Does anyone know a Best-Practice tutorial about this?

Implementing a HTTP/TCP/UDP/UNIX-Socket would be one solution for interaction.

An other solution would be reading external resources and placing commands in a file for example.

What is your way to implement this?

Is there a technical term for interaction with a running thread?

Thanks in Advance

User8461
  • 113
  • 1
  • 1
    https://stackoverflow.com/questions/1078695/what-remoting-approach-for-java-application-would-you-recommend – max630 Jan 06 '19 at 01:07
  • Thanks. RMI (Remote Method Invocation), SOAP(Simple Object Access Protocol) and JMS (Java Message Service) are too complex for my application. A simple pure java solution for sending a string (being interpreted as command) to a running app would be sufficient. – User8461 Jan 06 '19 at 01:24
  • In case you end up expanding on your cli and want a good framework for them, I highly recommend [pico cli](https://picocli.info/) – J Lewis Jan 07 '19 at 09:37

1 Answers1

1

I would use a TCP (or maybe UDP) connection.

The client would send commands via TCP to the server, and the server could answer (e.g. OK or NAK).

Format of the commands could be simple text strings (maybe separated with ;), XML or a binary format depending on your needs.

Simon
  • 1,774
  • 12
  • 15