Glassfish 4.x: using .reload mechanism in Eclipse?

123 views Asked by At

When I go to the Glassfish 4.x admin frontend and use the path to the unpackaged Eclipse build folder instead of uploading a WAR file, a simple "touch .reload" will trigger a relatively fast reload of the webapp container. However, when using the Eclipse plugin for Glassfish, the entire app gets packaged into a war and deployed after updating some class, which seems to be a really stupid thing to do during development.

Is there any possibility to make the .reload mechanism work in Eclipse?

From the command line, this can be done via

./asadmin redeploy --name jersey-war-example-1

which even eliminates the polling. Now I need to somehow turn this into an Eclipse build extension that does not start up a java instance just for that.

1

There are 1 answers

0
user1050755 On

If the current platform supports inotify, one can hook it up to the Glassfish RESTful API to trigger deployment reload on any changes:

#!/bin/bash

webappdir=`pwd`/target/jersey-war-example-1.0-SNAPSHOT

while inotifywait -e close_write -r $webappdir; do
        curl -v -H 'Accept: application/json' \
        -X POST \
        -H 'X-Requested-By: loadr' \
        -F force=true \
        -F id=$webappdir \
        -F isredeploy=true \
        -F virtualservers=server \
        -F contextRoot=/ \
        -F name=jersey-war-example \
        http://localhost:4848/management/domain/applications/application
done

One just has to make sure that updated class files get written to the correct folder. When using maven, add this to pom.xml:

<build>
    <!-- make compile-on-save work with app servers serving from the webapp build directory -->
    <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/classes</outputDirectory>

That way not even the polling mechanism and its implicit delay is needed, no JVM startup for the admin CLI either. The same is possible for WildFly 11. A BASH script doing this for both servers is available at https://gist.github.com/jjYBdx4IL/55334bc09e635c6e8d7a2fa30b2919ef.