Skip to main content

APIzation: Replication Package

[Q#460567][A#460590] How to mix java webstart with RMI?

https://stackoverflow.com/q/460567

I want to distribute a webstart application which uses RMI. I want to avoid to ask the user the address of the RMI server, because the website that distributes the application is also the RMI server. Furthermore, I don't know the address of the server at build time, therefore the address must be added with ad hoc configuration to the JNLP, or the address must be provided at execution time. This is the preferred way: is it possible to do so?

Answer

https://stackoverflow.com/a/460590

I haven't used Java RMI exactly (I've only used Java Web Start with Hessian binary protocol for doing something like RMI), but at least the part of passing the server address to the Web Start client app should be easy. When you generate the JNLP file in your application, add the address as a property: Then, in client code read that property: I assume here the website that distributes the application knows its own address :) Edit (with the additional limitation of not knowing address at build time): Hmm, Is the website distributing the app a dynamic or static one?

APIzation

<jnlp>
  [...]
  <resources>
    [...]
    <property name="serverAddress" value="..." />
  </resources>
</jnlp>
String serverAddress = System.getProperty("serverAddress");
package com.stackoverflow.api;

public class Human460590 {

  public static String getServerAddress() {
    return System.getProperty("serverAddress");
  }
}

package com.stackoverflow.api;

/**
 * How to mix java webstart with RMI?
 *
 * @author APIzator
 * @see <a href="https://stackoverflow.com/a/460590">https://stackoverflow.com/a/460590</a>
 */
public class APIzator460590 {

  public static String mixWebstart() throws Exception {
    return System.getProperty("serverAddress");
  }
}