Bck2BrwsrViaCLI

From APIDesign

(Difference between revisions)
Jump to: navigation, search
Current revision (06:25, 17 January 2017) (edit) (undo)
(Old Archetype with Query API)
 
(20 intermediate revisions not shown.)
Line 1: Line 1:
-
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. Type:
+
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:
 +
 
 +
<source lang="java">
 +
$ mvn archetype:generate \
 +
-DarchetypeGroupId=com.dukescript.archetype \
 +
-DarchetypeArtifactId=knockout4j-archetype \
 +
-DarchetypeVersion=0.16
 +
-Dwebpath=client-web
 +
</source>
 +
 
 +
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
<source lang="bash">
<source lang="bash">
-
$ mvn archetype:generate -DarchetypeGroupId=org.apidesign.bck2brwsr \
+
$ mvn package
-
-DarchetypeArtifactId=mojo -DarchetypeVersion=0.3-SNAPSHOT \
+
$ mvn -f client process-classes exec:exec
-
-DarchetypeRepository=https://maven.java.net/content/repositories/snapshots
+
</source>
</source>
-
[[Maven]] will download its libraries. The it asks you few questions (for example name of the project you want to create) and generate the skeleton project for you. Then just switch to the create subfolder:
+
to run the application in [[FXBrwsr]] mode (suitable for debugging). To run the application in real browser, use:
<source lang="bash">
<source lang="bash">
-
$ cd nameofyourproject
+
$ mvn -f client-web clean package -DskipTests bck2brwsr:show
</source>
</source>
-
and you are ready to compile and launch your first [[Bck2Brwsr]] project:
+
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:
<source lang="bash">
<source lang="bash">
-
$ mvn process-classes org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr
+
$ 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
</source>
</source>
-
a browser window will open and you can check how easy it is to synchronize content of various elements on the [[HTML]] page, to compute derived properties and how to draw a text on a [[HTML]] canvas.
+
When unzipped on the server, it is also wise idea to configure it to serve the ''bck2brwsr.js'' as a [[GZip]]ed file. That will get its size to ~200KB.
-
Of course, you don't have to work only from command line. [[Good]] IDEs, including [[NetBeans]] will open the generated project and provide you all comfort you are used to when coding in [[Java]].
+
==== [[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 [[AnnotationProcessor]]s 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:
 +
 
 +
<source lang="bash">
 +
$ mvn -Pdesktop -f client clean install
 +
$ unzip client/target/*-javafx.zip
 +
$ java -jar *-app/*jar
 +
</source>
-
Enjoy [[Java]] which has just returned [[bck2brwsr]]!
+
and the application starts with a [[JavaFX]] WebView and displays your page in it. More info at [[DukeScript]] [https://dukescript.com/update/2015/02/05/New-Version-of-Dukescript.html getting started] page.

Current revision

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.

Contents

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.

Personal tools
buy