added the ability to run the sample either in a web browser or in Java 7 with JavaFX and the KoolApp browser

This commit is contained in:
James Strachan
2012-05-29 08:50:12 +01:00
parent 2898abb245
commit 13dfda92d1
3 changed files with 102 additions and 0 deletions
@@ -4,6 +4,8 @@ This (really simple ;) application shows how to use Kotlin and the maven plugin
The source [Hello.kt](https://github.com/JetBrains/kotlin/blob/master/libraries/examples/browser-example/src/main/kotlin/sample/Hello.kt) uses the [kotlin.browser](http://jetbrains.github.com/kotlin/versions/snapshot/apidocs/kotlin/browser/package-summary.html) API to access the *document* property to modify the HTML.
### Running the sample in a web browser
To run the example try:
cd libraries/examples/browser-example
@@ -11,3 +13,30 @@ To run the example try:
open sample.html
This should open a browser which then shows some simple HTML which then includes some dynamically generated content.
## Running the sample on Java 7 with JavaFX and KoolApp's browser
You can also run the sample as Java code on a JVM using JavaFX (which includes its own webkit rendering engine for HTML / CSS / JS support) using the [KoolApp JavaFX browser](https://github.com/koolapp/koolapp/blob/master/koolapp-javafx/ReadMe.md).
First you need to install [Java 7 update 4](http://www.oracle.com/technetwork/java/javase/overview/index.html) or later which ships with JavaFX.
You will need to setup **JAVA_HOME** and **PATH** environment variables to point to the latest JDK. If you install Java 7 and use a Mac you might want to run this first...
export JAVA_HOME=/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
You can check you have JavaFX in your JDK install via
ls -l $JAVA_HOME/lib/javafx-mx.jar
which should find the javafx jar.
### Running the sample in JavaFX
To run the sample try...
mvn -Pjavafx
Assuming you've Java 7 enabled and JAVA_HOME points to the JRE/JDK for Java 7 or later.
This should popup a JVM process with an embedded webkit based browser running the application; using the compiled bytecode on the JVM rather than JavaScript.
@@ -23,6 +23,7 @@
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
@@ -50,4 +51,60 @@
</plugins>
</build>
<profiles>
<!-- runs the JavaFX UI - Requires Java7 update 4 or later -->
<profile>
<id>javafx</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.koolapp</groupId>
<artifactId>koolapp-javafx</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>run</id>
<phase>test</phase>
<configuration>
<target>
<java fork="true" classpathref="maven.test.classpath" classname="org.koolapp.javafx.namespace">
<arg value="file://sample-javafx.html"/>
</java>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>snapshots.fusesource.org</id>
<name>FuseSource Snapshots Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</profile>
</profiles>
</project>
@@ -0,0 +1,16 @@
<html>
<head>
</head>
<body>
<h1>Kotlin Sample</h1>
<div id="foo">
</div>
<script type="text/kotlin">
sample.namespace.myApp()
</script>
</body>
</html>