All Projects → jtulach → bck2brwsr

jtulach / bck2brwsr

Licence: other
Bck2Brwsr VM to transpile Java bytecode to JavaScript

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to bck2brwsr

Appbundle Maven Plugin
Maven plugin that creates an Application Bundle for OS X containing all your project dependencies and the necessary metadata
Stars: ✭ 163 (+75.27%)
Mutual labels:  jvm, maven-plugin
Java-Rule-Book
Basic concepts of Java to answer any question about how Java works
Stars: ✭ 36 (-61.29%)
Mutual labels:  jvm
graalvm
A Cloud Native Buildpack that provides the GraalVM implementations of JREs and JDKs
Stars: ✭ 21 (-77.42%)
Mutual labels:  jvm
probes-api
Software Activity Metering - Probes Open API
Stars: ✭ 31 (-66.67%)
Mutual labels:  jvm
escapin
Escapin is a JS/TS transpiler for escaping from complicated usage of cloud services and APIs
Stars: ✭ 20 (-78.49%)
Mutual labels:  transpiler
iokk
International Obfuscated Kotlin Contest
Stars: ✭ 56 (-39.78%)
Mutual labels:  jvm
JavaResolver
Java class file inspection library for .NET.
Stars: ✭ 39 (-58.06%)
Mutual labels:  jvm
wasm2kt
Web Assembly to Kotlin and Java converter. Allows to compile a C or C++ program/library, and generate a Kotlin or Java program/library.
Stars: ✭ 20 (-78.49%)
Mutual labels:  jvm
splunk-otel-java
Splunk Distribution of OpenTelemetry Java
Stars: ✭ 39 (-58.06%)
Mutual labels:  jvm
delta
DDD-centric event-sourcing library for the JVM
Stars: ✭ 15 (-83.87%)
Mutual labels:  jvm
cyclonedx-maven-plugin
Creates CycloneDX Software Bill of Materials (SBOM) from Maven projects
Stars: ✭ 103 (+10.75%)
Mutual labels:  maven-plugin
micrometer-jvm-extras
A set of additional JVM process metrics for micrometer.io.
Stars: ✭ 113 (+21.51%)
Mutual labels:  jvm
flamegrapher
Web frontend and REST API for Java Flight Recorder with Flamegraphs 🔥
Stars: ✭ 77 (-17.2%)
Mutual labels:  jvm
aspectj-maven-plugin
www.mojohaus.org/aspectj-maven-plugin/
Stars: ✭ 77 (-17.2%)
Mutual labels:  maven-plugin
js-slang
Implementations of the Source languages, which are small sublanguages of JavaScript designed for SICP JS
Stars: ✭ 41 (-55.91%)
Mutual labels:  transpiler
JavaInterview
JVM、JUC(高并发)、集合、计算机网络、数据库、MySql、Redis、、工作流(Activiti)、规则引擎(Drools)、Spring、SpringCloud、Mybatis、Git、Docker、Utils、Linux
Stars: ✭ 179 (+92.47%)
Mutual labels:  jvm
java-rust-ffi
🍋 FFI example for accessing Rust lang dynamic libraries from java
Stars: ✭ 37 (-60.22%)
Mutual labels:  jvm
Algorithm-Math
算法 & 数学知识 & 重拾基础知识系列文章编写和收集
Stars: ✭ 19 (-79.57%)
Mutual labels:  jvm
jvm
Pure Rust implementation of the JVM 7 specification
Stars: ✭ 27 (-70.97%)
Mutual labels:  jvm
play-scala-chatroom-example
Play chatroom with Scala API
Stars: ✭ 43 (-53.76%)
Mutual labels:  jvm

Build Status

Bring Java Back to Browser!

Bck2Brwsr VM is a Java virtual machine which is capable to take bytecode and transpile it (either ahead-of-time - e.g. during compilation on desktop - or just-in-time, e.g. in a browser) into appropriate JavaScript code which does the same thing. As a result one can write in Java, compile with JavaC, run it with Bck2Brwsr in any modern browser.

Getting Started

If you have a Maven or Gradle project it is as easy as adding one plugin to get your Java application into browser. Imagine you have a simple hello world application in src/main/java structure of your project:

public class Hello {
    public static void main(String... args) {
        System.err.println("Hello from Java in JS!");
    }
}

then it is just about adding following plugin into your pom.xml:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apidesign.bck2brwsr</groupId>
                <artifactId>bck2brwsr-maven-plugin</artifactId>
                <version>0.51</version>
            </plugin>
        </plugins>
    </build>

and executing mvn clean install bck2brwsr:aot bck2brwsr:show - more info in a dedicated page.

It is similarly easy with Gradle. Just by adding (the same) single plugin and configuring your script to use it:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.apidesign.bck2brwsr:bck2brwsr-maven-plugin:0.51"
    }
}

repositories {
    mavenCentral()
}

apply plugin: 'bck2brwsr'

you'll be able to invoke ./gradlew bck2brwsrShow and see your Java application greetings from the browser. An in-depth tutorial is available as well.

How do I deploy?

Just copy the generated files to any web hosting service! No application server needed, no code needs to be executed on the server. The whole application is just a set of pages that can be copied anywhere. In case of Gradle it consists of:

$ find build/web/
build/web/
build/web/index.html
build/web/lib
build/web/lib/emul-0.51-rt.js
build/web/main.js
build/web/bck2brwsr.js

The structure of pages generated by Maven is similar with the primary HTML file being target/index.html.

Talking to Your Java Code

Once your application is running in the browser, you can interact with it from a console. Btw. output of System.out and System.err is primarily printed into the console. Open the console and try:

var System = vm.loadClass("java.lang.System")
System.exit(0)

and voilá! your browser is closed. Obviously the above snippet is more useful for other methods in your application than System.exit. You can use it to locate any public class and invoke any of its public static methods.

Launching

Browsers download scripts asynchronously, as such the vm.loadClass may not be immediatelly ready, but it may get loaded with a delay. To accomodate such restriction one can use a callback style of the above:

vm.loadClass("java.lang.System", function(System) {
  System.exit(0)
});

Usage of callback is recommended when executing the first Java method (as that usually means loading of new scripts) and is exactly what the default content of index.html does:

<script src='bck2brwsr.js'></script>
<script>
var vm = bck2brwsr('main.js');
vm.loadClass('Hello', function(mainClass) {
  mainClass.invoke('main');
});
</script>

The first line loads the Bck2Brwsr virtual machine. Then one fills it with transpiled code of one's application var vm = bck2brwsr('main.js'); together with required libraries. At the end one invokes main method of the Hello class using the callback syntax.

More?

More info at project home page. Questions to bck2brwsr group.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].