Hello good Stack Overflow people,
I do have a business problem and would like to get some answers/pointers/ideas on how to go about solving it. perhaps this has been mentioned in some other topic but so far I searched the internet but not able to find a straight answer..
Business Problem: One of our clients would like to have a Java web based application but launched as a desktop application. i.e. the client would like to double click on an icon some where on their desktop and get a browser window launched pointing to the URL/context of the web application which will be running locally on a Jetty server that will get started up when the user clicks on the icon.
So far I have figured out how to package my application and create an exe launcher (using install4j) (basically i created an executable jar file with jetty server and my web app packaged together with a startup class that will start Jetty server and point it to the context of the web application).
My problem is I have no idea how to start up a (native) web browser and point it to the URL/context of the web app.
I have found this code that launch the user’s default browser:
String url = "http://www.google.com";
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
which is good but not good enough. and the reason its not good enough is that when the user close the browser the Jetty server would still be running in the back ground. What I want is when the user closes the browser I also want to detect this event and close down the Jetty server (without using any active X or JavaScript please)
Some one have mentioned creating a JPanel and include a native browser inside it using some DJ native swing API but I have no clue as how to do this.
Any ideas?
Many thanks in advance
Here is a piece of code just FYI. You can fork native browser in a process and return a java Process object to your java code. You can invoke the
processObject.waitFor()method to wait for the invoked process to terminates.The Launcher :
The main class: