Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a command line interface in java for an existing web based application

I have created a web based application using JSP and Servlets and the application uses an SQL Server DB as its backend.

The architecture is like this:

  1. I have all my business logic in a jar file
  2. I have created my views using JSPs and am using servlets to interact with my business logic jar
  3. The jar connects to the database to persist and hydrate information, which is relayed to the JSP by my servlets.

My web application runs on a remote Tomcat server.

Now, I have been given a new requirement. I have to create a command line interface, where I should be able to specify a list of commands and hit enter (or alternatively, create a set of commands and save it in a .bat file or something, and run it), so that my application performs the necessary actions. Basically, I have to create a command line interface, which can be used along with the GUI i already have (JSPs).

I am totally new to this. Can anyone throw light on where and how I can start?

Any little help is greatly appreciated.

EDIT

This is what my web application does. User can see a list of test scripts (written in Selenium WebDriver). He can choose script(s), choose a host on where to run them from, and click "Run", and the test executes on the said machines.

Now, I want a command line interface, which will eliminate the need for the GUI. Let's say, I simply want the user to be able to type a command like "execute My_Script_1", and the script should be executed.

The test scripts, the selenium drivers, everything reside on the App server.

My command line interface should be able to work on Windows command prompt.

Thank you.

like image 485
Sriram Sridharan Avatar asked Jun 09 '26 17:06

Sriram Sridharan


2 Answers

Are you using Spring? Can you specify, what exactly your CLI should do?

You may do, what Thomas said. You also may use template engines like Velocity.. To form your output. Use some kind of JavaCurses-like library to make your output... Look well.

Specifying commands... Hm.. think about your business logic what exactly you are showing to user. Remember webapp ui is webapp ui. Console ui is different. And user expects different behaviour

So commands like

show goods category="for kids"

Will be great. Also don't forget about different help commands yourJarName.jar --help / -h and etc

If your are want to write application with interactive mode... think about help command there.

like image 153
ppopoff Avatar answered Jun 12 '26 07:06

ppopoff


You say you have your business logic in a JAR.

Why not starting another project with this JAR as a dependency and build it as an executable jar ? Then simply use System.in and System.out to interact with the user.

EDIT :

So your application is hosted. Do you have an API like REST or SOAP or any other ?

Then you can build a client reading a string that the user has written, parsing it and calling the right service in your API.

like image 45
Thomas Avatar answered Jun 12 '26 09:06

Thomas