【问题标题】:Wildfly Maven plugin + hot deploymentWildfly Maven插件+热部署
【发布时间】:2015-11-03 19:13:22
【问题描述】:

我有一个 Java Spring 应用程序,在 Eclipse Mars 中配置,我在 Eclipse 中运行 Wildfly 9。我正在使用 wildfly-maven-plugin 部署到服务器。

这些是我遵循的步骤:

从 Eclipse 启动服务器并进行 Maven 构建,这也将应用程序部署到服务器。我可以在“成功部署”的服务器上看到大量日志,并且可以在浏览器中访问我的应用程序。它在“/standalone/data/content”下创建一个文件夹,但在“standalone/deployments”下没有war或exploded WAR

如果我更改了一些代码并将其保存在 Eclipse 中,(我已选中自动发布复选框并在保存时构建),服务器日志显示:将部署“myApp.war”替换为部署“myApp.war”内容从位置“独立\数据\内容...”

我看到在步骤 1 中创建的 prev 文件夹已被删除,myApp.war 已添加到部署文件夹中。但现在我无法在浏览器中访问我的应用程序。

auto-deploy-exploded="true"

那是在standalone.xml的部分。

【问题讨论】:

    标签: maven jboss wildfly


    【解决方案1】:

    对于 Eclipse,您可以使用 JBoss Tools 插件:http://tools.jboss.org/

    【讨论】:

      【解决方案2】:

      wildfly-maven-plugin 使用管理操作部署应用程序。它不部署任何展开的内容,只部署存档。换句话说,您需要在重新部署之前重新创建部署存档,否则将看不到更改。

      正如@ozOli 所说,最好使用 JBoss 工具。

      有一个开放的issue 允许部署展开的内容。这目前仅建议用于run 目标,但它也可能会扩展到部署爆炸内容。我认为部署爆炸式内容是可行的。

      虽然“热部署”的问题通常是源需要重新编译然后重新部署。 redploy 是注释的关键,需要重新扫描。

      【讨论】:

        【解决方案3】:

        Wildfly 具有管理 REST 支持。不需要花哨的工具。

        这是一个用于 Maven 项目的 Wildfly 和 Glassfish 自动重新部署的 BASH 脚本,即。在 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
        

        只需使用 mvn clean wildfly:run 启动 Wildfly 实例。

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-05-06
          • 2015-08-07
          • 2015-04-02
          • 1970-01-01
          • 2016-05-10
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多