Search code examples
javaunixcommand-linenio

Access running java program from shell command


I am looking for a way to access running java program from command line. The best woud be something that does the following:

Starting java app:

bash$java -jar MyBundle.jar App

Accessing app:

bash$test.sh param1 param2

So, test.sh calls App from MyBundle.jar somehow and passes values param1 & param2.

Important: I am looking for very fast approach. App hold database connection and it is very expensive to start App every time I need access do DB.

I need solution that will work in Ubuntu and Debian. If it will work on Mac - great.

Any help is appreciated!


Solution

  • I think you need to take a client-server approach. You app is the server, it runs as a background process and listens for connections on some port. And your client makes requests to the server and gets back the response.

    A fast and simple way of implementing this in java would be to wrap your app in the Jetty servlet container. You could set it up to return JSON responses for example, which are easy to process.