1

In the JNLP file how do I get the IP address automatically? Example:

<?xml version="1.0" encoding="utf-8"?> 
<jnlp spec="1.0+" codebase="GET ip address here automatically" href="Test.jnlp">

instead of manually setting the address to: codebase="http://10.10.10.1/"

Eric Wilson
  • 57,719
  • 77
  • 200
  • 270
jadrijan
  • 1,438
  • 4
  • 31
  • 48

4 Answers4

3

The JNLP file is a static resource. To do something like that you would need to use some sort of dynamic server side technology, such as JSP, to represent the JNLP.

laz
  • 28,320
  • 5
  • 53
  • 50
1

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;
}
Community
  • 1
  • 1
Lee Chee Kiam
  • 11,450
  • 10
  • 65
  • 87
1

It can't do that.

You can add a DNS entry for 10.10.10.1, and put the hostname in that field instead of the IP address, but it's just XML - there's no way to call a method from that line to run code and figure out what IP address it should connect to.

jefflunt
  • 33,527
  • 7
  • 88
  • 126
  • 1
    Thank you very much. I am sorry I just realized that the question I posted is very dumb. All I had to do was remove codebase completely for it to work. I find that JAVA documentation is all over the place and that is sometimes I ask stupid questions. – jadrijan Dec 05 '11 at 16:49
  • No worries. We all see things differently, and what might be obvious to some, is confusing to others. Happens to me all the time. – jefflunt Dec 05 '11 at 16:58
1

Have a look at the official documentation about relative addresses, which might help (you can avoid specification of the server address altogether): http://docs.oracle.com/javase/6/docs/technotes/guides/jweb/applet/codebase_determination.html

Chris Dennett
  • 22,412
  • 8
  • 58
  • 84
  • Thank you very much. I am sorry I just realized that the question I posted is very dumb. All I had to do was remove codebase completely for it to work. I find that JAVA documentation is all over the place and that is sometimes I ask stupid questions. – jadrijan Dec 05 '11 at 16:49