0

I've found exactly the same question I just made but it is 7 years old; so I'd like to have an "updated" answer if it is possible. Thanks.

Andrew Thompson
  • 163,965
  • 36
  • 203
  • 405
Tia
  • 5
  • 4
  • My "updated" answer is: *don't*. Best to use the best and most up-to-date technology available, and Swing GUI's are not it. For my money, I'd go with JavaScript/CSS/HTML if the task were mine. And I consider myself to be a Swing expert – Hovercraft Full Of Eels Apr 11 '20 at 21:43
  • One solution that might work for you is https://www.webswing.org/ – George Z. Apr 11 '20 at 21:45
  • 2
    The two main technologies that would have allowed you to launch a Swing application from a Browser were Java WebStart and Java Applets. Both have been more or less discontinued a this point. What is it exactly that you're trying to achieve? There may be something that can help you get half-way there. Hypothetical example: Java > JavaScript translation. – TrogDor Apr 11 '20 at 21:45
  • *"I've found exactly the same question"* Where (link please)? With the link, we can add a comment or edit answers to reflect the current situation, thus updating them to warn people and save them the trouble of asking a duplicate question. – Andrew Thompson Apr 11 '20 at 23:52

2 Answers2

5

Old days

As commented by TrogDor, there were previously two ways to deploy a Swing app through the web:

  • Java Applet technology
    Your app would appear within a rectangle on the web page, within the browser.
  • Java Web Start technology
    Clicking a link on a web page would download a copy of your Swing app to the user’s local machine, where your app would then be launched locally using a locally-installed JVM. So your app runs separate from the web browser. This click-to-download-and-run process is defined by Java Network Launching Protocol (JNLP).

Both of these are being phased out.

➥ For details, see the white paper Java Client Roadmap Update published by Oracle, updated 2020-05-11.

Nowadays

The modern approach is to build a Swing and/or JavaFX app, then deploy by using a packaging tool to include a JVM. You end up with a complete self-contained self-launchable application.

This means you need multiple builds, one app for each platform your users may deploy on (macOS, Linux, BSD, Windows, and so on). While that is an additional burden to you, the flip-side is that you control exactly what version of Java is being used to run your app.

Because of the Java Platform Module System (JSR 376) in Java 9 and later, you can now strip down the bundled JVM and libraries to include only the parts actually used by your particular app.

The build tools for packaging your app have been rapidly evolving in recent years. So be sure to do your research to find the most robust and modern tooling.

Alternatives

You might consider any of these alternatives:

  • OpenWebStart
    A re-implementation of Java Web Start
  • GraalVM
    Ahead-of-time native-code compilation of your Java app
  • Vaadin Flow
    Using Java to build desktop-style apps delivered as web apps

OpenWebStart

You might be interested in a separate implementation of Java Web Start technology.

While Oracle is phasing out Java Web Start, there is an open-source implementation of JSR 56: Java Network Launching Protocol and API called OpenWebStart. See GitHub. This project is currently maintained by the company Karakun, based on the IcedTea-Web core functionality developed at Adoptium (née AdoptOpenJDK).

GraalVM

A cutting-edge alternative is to build an entirely native-code ahead-of-time compiled version of your app using GraalVM.

Vaadin Flow

An entirely different way to build a web app by using Java is the Vaadin Flow framework.

You specify your user-interface layouts with widgets in a manner quite similar to Swing, specifying an arrangement of widgets (buttons, fields, labels, etc.). You can do so using your choice of straight Java code, an XML-based description language, or a visual design tool.

At run-time, Vaadin automatically automatically generates the HTML, CSS, and JavaScript necessary to render your app remotely on the client user’s machine within a web browser. So, you have pure Java on the server-side, and no Java on the client-side, just Web standards technologies built into all modern browsers.

More info

All of this has been covered many times already on Stack Overflow. So search to learn more.

For tips on obtaining a JVM to bundle with your app, see How to get java 11 run-time environment working since there is no more jre 11 for download?.

Basil Bourque
  • 218,480
  • 72
  • 657
  • 915
0

Nowadays you can run Swing app on server with UI in the browser. You can find example here: https://github.com/JetBrains/projector-demo.

v_bogdanov
  • 31
  • 1