JavaQuery API and Demo

Java.net - The Source for Java Technology Collaboration

License

License

Categories

Categories

IDE Development Tools
GroupId

GroupId

org.apidesign.bck2brwsr
ArtifactId

ArtifactId

javaquery
Last Version

Last Version

0.30
Release Date

Release Date

Type

Type

pom
Description

Description

JavaQuery API and Demo
Java.net - The Source for Java Technology Collaboration
Project Organization

Project Organization

API Design

Download javaquery

Filename Size
javaquery-0.30.pom 740 bytes
Browse

How to add to project

<!-- https://jarcasting.com/artifacts/org.apidesign.bck2brwsr/javaquery/ -->
<dependency>
    <groupId>org.apidesign.bck2brwsr</groupId>
    <artifactId>javaquery</artifactId>
    <version>0.30</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/org.apidesign.bck2brwsr/javaquery/
implementation 'org.apidesign.bck2brwsr:javaquery:0.30'
// https://jarcasting.com/artifacts/org.apidesign.bck2brwsr/javaquery/
implementation ("org.apidesign.bck2brwsr:javaquery:0.30")
'org.apidesign.bck2brwsr:javaquery:pom:0.30'
<dependency org="org.apidesign.bck2brwsr" name="javaquery" rev="0.30">
  <artifact name="javaquery" type="pom" />
</dependency>
@Grapes(
@Grab(group='org.apidesign.bck2brwsr', module='javaquery', version='0.30')
)
libraryDependencies += "org.apidesign.bck2brwsr" % "javaquery" % "0.30"
[org.apidesign.bck2brwsr/javaquery "0.30"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • api
  • demo-calculator

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.23</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.23"
    }
}

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.23-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.

Versions

Version
0.30
0.21
0.20
0.19
0.18
0.17
0.16
0.15
0.14
0.13
0.12
0.11
0.10
0.9
0.8.1
0.8
0.7.2
0.7
0.6
0.5
0.4