It turns out, these are all problems which have already been solved within the JVM. The problem is, the JVM has historically been restricted to an isolated/sandboxed container known as an applet. This sandboxing made it difficult to perform even basic operations like manipulating the DOM, and ultimately lead to the downfall of Java within the browser.
JavaPoly is both a specification and a reference implementation. The specification is intended to be implemented by Chrome and Firefox, with other browsers to follow. The JavaPoly spec may be implemented in addition to (or in place of) other proposals.
The most prominent alternatives are:
For these reasons, the most reliable technique is to access classes using `JavaPoly.type('com.yourpackage.YourClass')`, which returns a promise to provide the requested class.
Browsers which natively support the JavaPoly specification can safely reference Java classes by directly referencing classes using their fully-qualified name, but until there is widespread support for this technique, using JavaPoly.type(...) is the recommended method of referencing classes when targeting legacy browsers.
Polyfills are bound by the browser's same-origin policy, which restricts the plugin's ability to load libraries from remote hosts/protocols. If you run into an issue loading remote java files, consider setting the appropriate CORS headers (like `Access-Control-Allow-Origin: *`) on the remote server.
By default, JavaPoly starts a single JVM for your website. However, it is sometimes useful to explicitly start your own JVMs (so you can have multiple JVMs for process isolation, or because you want to start the JVM using non-default configuration options).
Advantages of running in a separate thread/context:
Disadvantages of running in a separate thread/context:
JavaPoly is completely open source, and contributions are welcomed. The source code is available at git.javadeploy.net/jimsproch/JavaPoly. JavaPoly utilizes the Doppio JVM, and engineers interested in contributing are encouraged to check out the Doppio source code. If you are interested in contributing to JavaPoly, the best way to get your feet wet is with the doppio starter task.