Get server address in Java Web Start
How can I get server ip开发者_运维知识库 address in my JavaWS application, from which it was downloaded?
Thanks!
I guess, use BasicService.getCodeBase
.
You'll need to get ahold of jnlp.jar and add it to your application. I had to find it in the JDK samples and demos, which are distributed separately from the JDK. I used this samples and demos question to find it. I was able to get ahold of it with a URL like http://download.oracle.com/otn-pub/java/jdk/8u11-b12-demos/jdk-8u11-windows-i586-demos.zip
With jnlp.jar on your classpath, use this code to get the URL of your application's codebase, which you can use to find the server hostname.
import javax.jnlp.*;
BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
URL codebase = bs.getCodeBase();
精彩评论