'. '

Bck2Brwsr

From APIDesign

Revision as of 09:01, 1 March 2013 by JaroslavTulach (Talk | contribs)
Jump to: navigation, search

During my duties at JavaOne2012 my feeling (primed by observing various RSS feeds full of posts about something which ends .js) that Java is no longer as cool as it used to be straightened. It always starts by loosing interest of newcomers, targeting just a piece of the technology segment and soon once Good Technology becomes new COBOL. Can that happen to Java? Just read Is JavaScript the Future of Programming? and (if you like Java), you'll get scared. I decided to do something about that. I'd like to return my favorite programming language Bck2Brwsr.

Contents

Goals

Create small Java capable to boot fast and run in 100% of modern browsers including those that have no special support for Java.

Demonstrate that Java has benefits over JavaScript when creating larger HTML5 applications.

Unlike other similar efforts, the goal of this project is not to execute any existing Java library. It is expected that libraries for the new, limited environment need to be specially designed.

Demo

Right now there are two compilator demos. One is generating the JavaScript during compile phase (try here). That is no longer the most interesting one.

There is also a demo that is using classes packaged in JAR files. That is in my opinion more interesting as it shows how easy it is to reuse (simple) libraries in your browser as well as on your server. Try it here!


Try It Yourself!

The Bck2Brwsr project is publishing artifact snapshots to Maven repository since Feb 13, 2013. That means there is an easy, three steps, way to start coding for the browser yourself. All you need is Java and Maven installed.

Knockout4Java + Bck2Brwsr Archetype

The latest archetype now focuses on integration with Knockout4Java and its execution in Bck2Brwsr (for deployment) and FXBrwsr (for debugging) modes:

$ mvn archetype:generate \
	-DarchetypeGroupId=com.dukescript.archetype \
	-DarchetypeArtifactId=knockout4j-archetype \
	-DarchetypeVersion=0.16
        -Dwebpath=client-web

Possibly replace the 0.16 version with newer version if/when available. Maven will download its libraries. Then it asks few questions (for example name of the project you want to create) and generates the skeleton project for you. When the project is successfully created, switch to the created subfolder and execute following command in it

$ mvn package
$ mvn -f client process-classes exec:exec

to run the application in FXBrwsr mode (suitable for debugging). To run the application in real browser, use:

$ mvn -f client-web clean package -DskipTests bck2brwsr:show

Of course, you don't have to work only from command line. Good IDEs, including NetBeans will recognize the generated project without any struggle and provide you all the comfort you are used to when coding in Java.

Deploying to Server

When your application is ready you can easily deploy it to a server as a set of static pages:

$ mvn clean install
$ unzip client-web/target/*-bck2brwsr.zip
# to test it try firefox
$ firefox public_html/index.html 
# or chrome in a relaxed security mode (needed only on local disk):
$ google-chrome --allow-file-access-from-files public_html/index.html

When unzipped on the server, it is also wise idea to configure it to serve the bck2brwsr.js as a GZiped file. That will get its size to ~200KB.

Eclipse Support

Yesterday we (Jonathan Fuerth watched by me) managed to open the generated (and compiled) project in Eclipse. Showed up without errors after adding target/generated-sources/annotations/ as additional source path root. The support for AnnotationProcessors was limited, when we added new @Property(...), we needed to recompile for the IDE to realize what is going on. However the behavior seems acceptable and certainly better than I expected given the fact nobody tested it and designed for it yet.

Deploy as a Desktop Application

One can also build classical Java desktop application and deploy it to users as a ZIP file:

$ mvn -Pdesktop -f client clean install
$ unzip  client/target/*-javafx.zip
$ java -jar *-app/*jar

and the application starts with a JavaFX WebView and displays your page in it. More info at DukeScript getting started page.

TODO

Although the system is capable to run and execute trivial applications, there remains tons of things to improve and fix. Any help is welcomed. Just let me know if something interests you:

  • Speed - use Graal's flow analyzer
    • look into the GraphBuilderPhase class and see how it creates SSA form (using FrameStateBuilder)
    • BciBlockMapping class that is used for creating structured control flow from byte codes.)
  • More precise int64 support - Martin Š. working on
  • Convertor from GWT's native code to Bck2Brwsr's @JavaScriptBody - Lahváč created a hint. Igor works on Ant task.
  • Method and field overriding with various modifiers
  • Compatibility tests
  • Basic reflection support (e.g. Bck2Brwsr throws SecurityException when allowed),
    • Done: Class.newInstance() works.
    • Done: Class.getMethods() works (returns only public methods)
    • Done: Annotations of classes and methods
  • Debugger of Java (and not JavaScript would be good)
  • Support for MVVC like Knockout.js
    • Done: Binds String and primitive types
    • Bind array types
    • Bind complex classes
  • Packaging into a static website via JAR files
    • Implement java.util.zip APIs

Done

  • Throwing and catching exceptions by Tomáš Z., finally block by me.
  • Support for converting ByteCode in the browser
  • Speed via register based system - Ľubomír finished first version of his register based rewrite on Dec 14, 2012.
  • Speed benchmark and infrastructure to measure it in various environments - Martin Š.
    • Run with -Dvmtest.brwsrs=firefox,chromium-browser (or any other browsers you want to test)
  • Maven archetype for creating the calculator like demos
  • Int32, Int16, Int8 arithmetics done by Martin Š.
  • API for drawing on the canvas: Thanks Toni! Read about his experience using Bck2Brwsr.
Personal tools
buy