Is there a modern way to run java applications in browser?
Asked Answered
P

4

7

Is there a modern way to run java application on the web? As far as I know, java applets and java web start both are deprecated.

I have an android app, written in java, which I want to run on server (of course, altered in some way). While java is cross-platform there is no problem to transfer it to desktop (no matter, javafx, swing or etc.).

Apparently, it would be great not to re-write it in some other language.

Profiteer answered 2/1, 2019 at 16:43 Comment(1)
There are JSP / Servlets and there is GWT.Tabatha
L
4

Nowadays, we're using GWT at work. Well.. It's efficient, it's fast and compatible with all browsers. And it's so easy to build a web page with GWT. You can check tutorials from this link.

And you can look up for Spring MVC. Not the most flexible choice for UI, I know. But give it a shot. link

But.. If you're open to new things, I'll totally recommend React Js. It's flexible,it's super fast with perfect UI. If you ever think of using Java just for back end, React js is a great deal for UI. link

Letendre answered 2/1, 2019 at 16:51 Comment(1)
Since you are using android I think GWT is the right choice. The Inbox app from Google is written largely in GWT so a lot of code is re-used between Android and the webapp.Schottische
M
2

Yes it's possible and I can guarantee if you follow this tutorial you will be shocked about how super easy is to use the Java Virtual Machine for modern web browsers which called CheerpJ.

CheerpJ is a WebAssembly-based Java Virtual Machine for the browser. It has extensive compatibility with Java 8 and provides a full runtime environment1 for running Java applications, applets, libraries, and Java Web Start / JNLP applications in the browser without plugins.

Here is a super easy example on JS run this:

<script src="https://cjrtnc.leaningtech.com/3.0rc2/cj3loader.js"></script>
await cheerpjInit();
const lib = await cheerpjRunLibrary("/app/example.jar");

const Example = await lib.com.example.Example;
const example = await new Example();
await example.hello(); 

And this is the Java method call:

package com.example;

public class Example {
  public String[] greetings = {"Hello", "Bye"};
  public void hello() {
    System.out.println("Example says hello!");
  }
}

Attention!!! the app is not a folder path in your project but instead, it refers to the root of web server for example app=http://localhost:8080/ for more info refer to this link

Megalomania answered 20/1 at 19:1 Comment(0)
W
1

Nowadays you should be able to run Java (and most other languages) in the browser throught WebAssembly (Wasm).

This answer recommends TeaVM.

There also is Bytecoder.

Waynant answered 25/10, 2023 at 15:41 Comment(0)
C
0

There is an HelloWorld Example Java-Program which is running in a browser:

https://github.com/neo-expert/jsjvm_helloworld

After compiling you can just run the jar file which starts a webserver where the program will be served. (port 8080)

Circumstantiate answered 30/5, 2020 at 11:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.