Livereload protocol implementation based on Netty websocket implementation.
The goal of this project is to provide a livereload Java implementation as lighweight as possible .
It is strongly inspired by livereload-jvm which is based on Jetty websockets.
Livereload in a nutshell
Livereload is a productivity tool for web developers. During web development, it refreshs the browser each time a file has been changed on the server side such as a CSS stylesheet or an HTML document.
How to enable reload in the browser
On the browser side the easiest way to include livereload.js into your application is to use a browser plugin. However it is not always possible to do so. If your application runs on a mobile device, on internet explorer or anywhere else where adding a browser extention is not an option, the fastest and more reliable way to include livereload.js is to use the following code fragment:
<script>document.write('<script src="http://' + (location.host || 'localhost').split(':') + ':35729/livereload.js"></' + 'script>')</script>
Snipset taken from the livereload-js website
How to start netty-livereload from the CLI
The simplest way to start a livereload server from the command line is to use the "all in one" jar as below:
java -jar netty-livereload-0.1-allinone.jar PATH
PATH being the path to the folder containing your web files.
This "all in one" jar is available for download from maven central
How to embed the livereload server in your application
First you need to add a netty-livereload dependency to your project. Below a maven XML fragment to add in the dependencies section:
<dependency> <groupId>com.github.alexvictoor</groupId> <artifactId>netty-livereload</artifactId> <version>0.1</version> </dependency>
Then you just need to create a WebSocketServer instance providing the path to your web files as a String. Port is optionnal, default value being 35729, which is the value specified in the livereload protocol specification.
Then you just need to start the server. Below a code example:
String rootFolder = "..."; WebSocketServer server = new WebSocketServer(rootFolder); server.start();