Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt, Livereload with maven and jetty server

I am wondering if its at all possible to use grunt and livereload with my current java web application that is using maven and jetty?

The way my current java web application works is that I run maven to build the webapp and it also creates a local jetty server with my java application running on it. I'd like to be able to have livereload using the jetty server, rather than having grunt create a new localhost server where it's looking for a index.html page to load.

Gruntfile.js (just a couple snippets from my gruntfile.js)

var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({
  port: LIVERELOAD_PORT
});
var mountFolder = function (connect, dir) {
  return connect.static(require('path').resolve(dir));
};

    connect: {
      options: {
        port: 9000,
        hostname: '*'
      },
      livereload: {
        options: {
          middleware: function (connect) {

            return [lrSnippet, mountFolder(connect, 'src/main/webapp/')];
          }
        }
      }
    },
    open: {
      server: {
        path: 'http://localhost:<%= connect.options.port %>'
      }
    }
like image 630
Anks Avatar asked Nov 01 '22 11:11

Anks


1 Answers

You can use this: https://github.com/davidB/livereload-jvm

The way I do it is: create a jetty server instance programatically and along with it create a LRServer (the above implementation also watches for changes in a folder of your choice and when it notices a change notifies the client/browser). To include the livereload.js client script, I depend on my framework to do it (Apache Wicket), I configure it to include the script in development mode.

I'm sure you can create a small maven plugin for this, or even spawn a new jvm through maven (using exec-maven-plugin for example http://mojo.codehaus.org/exec-maven-plugin/) with this livereload implementation.

like image 193
emerino Avatar answered Nov 09 '22 09:11

emerino