In the JNLP file how do I get the IP address automatically? Example:
If you host your JNLP file in a Java Web Container (e.g. Tomcat) instead of normal HTTP server (e.g. Apache Web Server), you may use JNLP Servlet provided by Sun https://stackoverflow.com/a/7593088/418439. Some interesting variables are $$codebase, $$site (see code below). For instance, $$site in JNLP file will be replaced by the hosting machine ip address and its port (E.g. http://10.10.10.1:8080
)
private String specializeJnlpTemplate(HttpServletRequest request, String respath, String jnlpTemplate) {
String urlprefix = getUrlPrefix(request);
int idx = respath.lastIndexOf('/'); //
String name = respath.substring(idx + 1); // Exclude /
String codebase = respath.substring(0, idx + 1); // Include /
jnlpTemplate = substitute(jnlpTemplate, "$$name", name);
// fix for 5039951: Add $$hostname macro
jnlpTemplate = substitute(jnlpTemplate, "$$hostname",
request.getServerName());
jnlpTemplate = substitute(jnlpTemplate, "$$codebase", urlprefix + request.getContextPath() + codebase);
jnlpTemplate = substitute(jnlpTemplate, "$$context", urlprefix + request.getContextPath());
// fix for 6256326: add $$site macro to sample jnlp servlet
jnlpTemplate = substitute(jnlpTemplate, "$$site", urlprefix);
return jnlpTemplate;
}