How to create a CLI like Spring Shell in Java EE a

2019-08-26 02:40发布

问题:

I used Spring shell in my project, which works very well.

Now we have a Java EE project on the JBoss application server. I would like to have a good CLI, just like the Spring shell. How can this be done?

回答1:

As far as I understand your request, Spring Shell is not meant for this. Spring Shell is somewhat tied to running in an actual terminal, leveraging JLine. Another implementation could be written (similar to the "running in IDE" approach) that scans for MethodTargets and runs them, taking input from your (custom) webapp.

Maybe http://www.crashub.org/ is more tailored to what you're asking for.



回答2:

I would expose all the JBoss services API via REST, using Swagger. Then generate the swagger.json and import it in Swagger Editor, generate automatically the Java client and invoke it from the Spring Shell client. I know it's a bit roundaboutish, but unfortunately as now I am not aware of how to integrate Spring Shell in a Java EE application. You can even automate the generation of the Java Client https://www.baeldung.com/spring-boot-rest-client-swagger-codegen