Reputation: 4346
I have a web application
I want to implement a command line function for tomcat console window, to read commands and perform some action or output some information to console. How can I do it?
Example: type "show memory", then display JVM memory information to console.
Can I do it just by System.in
? Will there be any thread-safe problem?
Upvotes: 1
Views: 295
Reputation: 48057
If you're running as a web application in Tomcat, you won't get any access to System.in or the console: Tomcat is typically started in the background, detached from all consoles. And it won't provide you witn meaningful access to the console.
The way to go is to either provide a REST API as suggested by @rlegendi in the comments (any other API would work as well) and write a separate command line application that interfaces with your API. Alternatively utilize the "manager" interface - if I remember correctly from ancient past, tomcat's manager application also has some usable methods to access from external scripts.
Make sure to make those calls authenticated - at least validate that they're coming from localhost so that you simulate some kind of security in the API. Don't trust random calls coming in from the world.
Upvotes: 1