0
votes

I have a Java Spring application, configured in Eclipse Mars and I am running Wildfly 9 from with in Eclipse. I am using the wildfly-maven-plugin to deploy to server.

These are the steps I follow:

Start the server from eclipse and do Maven build which also deploys the application to server. I can see whole lot of logs on server of "successful deployment"and I can access my application in browser. It creates a folder under "/standalone/data/content" but no war or exploded WAR under "standalone/deployments"

If I change some code and save it in eclipse, (I have checked Automatically publish check box and build on save), The sever logs says: Replaced deployment "myApp.war" with deployment "myApp.war" Content removed from location "standalone\data\content..."

And I see the prev folder created during step 1 is removed and myApp.war is added to deployment folder. But now I can not access my application in browser.

auto-deploy-exploded="true"

That is in the section of standalone.xml.

3

3 Answers

3
votes

The wildfly-maven-plugin deploys applications using management operations. It doesn't deploy any exploded content only the archive. In other words you'd need to recreate the deployment archive before you redeploy otherwise changes won't be seen.

As @ozOli says it's probably best to use JBoss Tools.

There is an open issue to allow exploded content to be deployed. This is currently suggested only for the run goal, but it could likely be expanded to deploy exploded content as well. I think deploying exploded content works.

In general though the issue with "hot deployments" is source needs to be recompiled and then redeployed. The redploy is key as annotations and such need to be rescanned.

1
votes

For Eclipse you can use the JBoss Tools plugins: http://tools.jboss.org/

0
votes

Wildfly has administrative REST support. No need for fancy tools.

Here is a BASH script for Wildfly and Glassfish auto-redeploy of Maven projects, ie. when working with auto-compile in Eclipse:

set -x

pubname=$1
usewar=$2
if [[ -z $pubname ]]; then
    pubname=ROOT
fi
if [[ -z "$usewar" ]]; then
    usewar=0
else
    usewar=1
fi
if ! webappdir=$(ls -d `pwd`/target/*-SNAPSHOT); then
    webappdir=$(pwd)
fi
iswildfly=0

ctxroot="/$pubname"
if [[ "$pubname" == "ROOT" ]]; then
    ctxroot="/"
fi

port=4848
if curl http://localhost:9991/ ; then
    port=9991
    iswildfly=1
elif curl http://localhost:9990/ ; then
    port=9990
    iswildfly=1
fi

if (( usewar )); then
    webappdir=$webappdir.war
    if ! (( iswildfly )); then
        webappdir="@"$webappdir
    fi
fi

wildflycmd() {
    local cmd=$1
    curl --retry 100 --retry-delay 3 --retry-connrefused --digest -L -u admin:admin -D - http://localhost:$port/management \
        --header "Content-Type: application/json" \
        -d "$cmd"
}

if (( iswildfly )); then
    wildflycmd '{"operation" : "composite", "address" : [], "steps" : [{"operation" : "undeploy", "address" : {"deployment" : "'$pubname'.war"}},{"operation" : "remove", "address" : {"deployment" : "'$pubname'.war"}}],"json.pretty":1}'
    if (( usewar )); then
    wildflycmd '{"operation" : "composite", "address" : [], "steps" : [{"operation" : "add", "address" : {"deployment" : "'$pubname'.war"}, "content" : [{"url" : "file:'$webappdir'"}]},{"operation" : "deploy", "address" : {"deployment" : "'$pubname'.war"}}],"json.pretty":1}'
    else
    wildflycmd '{"operation" : "composite", "address" : [], "steps" : [{"operation" : "add", "address" : {"deployment" : "'$pubname'.war"}, "content" : [{"path" : "'$webappdir'", "archive":"false"}]},{"operation" : "deploy", "address" : {"deployment" : "'$pubname'.war"}}],"json.pretty":1}'
    fi
fi

inotifyEvents=""
if ! [[ "$(uname)" =~ ^CYGWIN ]]; then
        inotifyEvents="-e close_write"
fi

while inotifywait $inotifyEvents -r $webappdir --excludei "\.(js|html|css)$" || :; do
    if ! (( iswildfly )); then
        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=$ctxroot \
        -F name=$pubname \
        http://localhost:$port/management/domain/applications/application
    else
        wildflycmd '{"operation" : "composite", "address" : [], "steps" : [{"operation" : "redeploy", "address" : {"deployment" : "'$pubname'.war"}}],"json.pretty":1}'
    fi
done

Just start the Wildfly instance with mvn clean wildfly:run.

Source: https://github.com/jjYBdx4IL/snippets/blob/master/java/jee_autodeploy.sh