I'm going to migrate a Java Applet to be started via JNLP as a Java Web Start Application and run into some troubles/missunderstandings ...
One of the resources I've got is this: 6 Migrating Java Applets to Java Web Start and JNLP:
But let's start:
Currently the application is an applet (JApplet
) and was started in past by embedding into an HTML with the applet tag referring to a JNLP.
Now since applet support was dropped by all browsers, I should run it as Java Web Start.
Simply calling same JNLP failed as the resources (JAR files) couldn't be loaded.
This was as a first step fixed by adding an code base attribute to the JNLP file.
Applet is starting outside of the browser.
But now the hard part ... I should/would like to get rid of any applet dependency.
But how?
What is the right approach for that?
The guide doesn't really tell, and therefore I have some questions:
applet.getAppletContext()
and related usage of it?I tried & to start the applet in different ways, but after that my applet was not starting any more.
How do I really replace it?
What should be the right wrapper for an application instead of applet?
How to start it?
Is there maybe a more elaborate guide/sample/tutorial to follow with a real example?
An alternative containment for you application could be a JFrame.
A migration path would be refactoring (moving) the actuall UI Code into a JPanel. That one can be placed into the JApplet or for an Java WebStart application into a JFrame. (during that time you could have a hybrid application).
<!-- main in MyApplication -->
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame();
frame.setTitle("MyApplication via JWS");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// add here the real UI to the frame: setUpGUI(frame);
frame.pack();
frame.setVisible(true);
}
});
}
<!-- Init() in MyApplication extends JApplet -->
@Override
public void init() {
EventQueue.invokeLater(new Runnable() {
public void run() {
// add here the real UI to the applet: setUpGUI(MyApplication.this);
}
});
}
Note: the EventQueue.
According Question 1:
Some of the Applet specifica have to be replaced be different ways.
Find the basics here: https://docs.oracle.com/javase/9/deploy/jnlp-api-examples.htm
e.g.: for AppletContext there is the BasicService as some kind of replacement.