Java standalone app with dynamic configuration via server over HTTP
i am writing a standalone java app. the app's properties should be configurable from a webpage deployed with the app. how do i achieve this ?
Thanks in advance
note: the app has an embedded HTTP开发者_如何学Go client/server module. it should only run from command prompt
I don't think that's a good idea. Webpage forms are designed to work with a server, not with a standalone client app. You could have the app run its own web server, but that would mean the app has to be running for the configuration page to work, and it's also a rather contrived setup just to do some configuration.
It might be possible for the webpage to contain JavaScript that writes to a local file - I don't know enough about the JavaScript security model to say.
But why not have the configuration dialog as part of the app's GUI? That's the normal and expected behaviour - you'd need a pretty compelling reason to deviate from it.
JMX might be the answer that you're looking for. If you expose all of your configurable properties through MBeans, then adding a web page on top of that exposing these properties is just configuration.
You can launch a standalone Java app using JNLP files (Java WebStart). If you want the user to be able to configure the application before its launched, you can have the JNLP file dynamically generated, then pass properties as environment variables through the JNLP file.
You can configure your standalone Java app to read configurable properties from a properties file (say conf.properties) on the server.
You may have a UI webpage (html/jsp) with all the field to be configured. When the page is submitted a JSP/Servlet may write/update the contents of conf.properties on the server.
UPDATE: The above solution will work assuming only an admin user wants to update the properties file. In case anybody should be able to update it, then concurrency issue has to be taken into account.
In that scenario, you have to implement a mechanism similar to how weblogic10 updates config.xml using Admin Console.
i.e. You will have 2 conf.properties files confA & confB (initially in sync). The standalone app will always read from confB. The UI will have 2 buttons say Lock & Release configurations. When an edit is made (locked & released), it will be written to confA and at the same time changes of confA has to be replicated to confB.
精彩评论