0

I am trying to automate my maven build and deployment process of the EAR in Jboss. I managed to write a bat file for the same which is given below.

    ECHO OFF
    RMDIR /S /Q .\deploy
    call mvn clean install -D build=P,JB
    call mvn clean install -D build=F,JB
    @echo | call C:\Work\jboss-as-7.1.1.Final\bin\jboss-cli.bat --connect --controller=[my-machine-name]:9999 command=:shutdown
    del /q C:\Work\jboss-as-7.1.1.Final\standalone\deployments\*.*
    xcopy /s /y .\deploy\function\Jboss\*.ear C:\Work\jboss-as-7.1.1.Final\standalone\deployments
    xcopy /s /y .\deploy\WorkFlowEngine\Jboss\*.ear C:\Work\jboss-as-7.1.1.Final\standalone\deployments
    cd C:\Work\jboss-as-7.1.1.Final\bin
    rmdir "C:\work\jboss-as-7.1.1.Final\standalone\data" /s /q
    rmdir "C:\work\jboss-as-7.1.1.Final\standalone\log" /s /q
    rmdir "C:\work\jboss-as-7.1.1.Final\standalone\tmp" /s /q
    standalone.bat -bmanagement  [my-machine-name] -b [my-machine-name] -c standalone-full-ha.xml
      {code for check of deployment success/failure}
    PAUSE

Here you can see that I am using the line

standalone.bat -bmanagement  sbstjwsvm1509 -b sbstjwsvm1509 -c standalone-full-ha.xml

My requirement is that I want to check if the EAR was deployed successfully from my bat file.One way which I thought of is to check for .deplyed or .failed extension files in the Jboss deployment folder.I tried to write codes for the same but my code which is written below the above mentioned line is not getting executed.Is there any other means by which I can achieve this?Or what am I doing wrong in my bat file?Why is my code to check for deployment not getting executed?

Deepak Shajan
  • 911
  • 1
  • 7
  • 19

2 Answers2

1

Because the standalone.bat isn't executing in background and will be running the JBoss instance until you kill/stop it (ctrl+C signal or like you shutdown through jboss CLI). See this answer to get examples and details about you want to achive.

Since you are using maven, I suggest you to use jboss-as-maven-plugin. Take a look the Usages, you will find commands to deploy/undeploy applications, resources, and to start/stop the server.

Then you could integrate the plugin execution to stop/clean in the maven clean phase and deploy/start on maven install phase using goals. See complex examples.

Community
  • 1
  • 1
Guillermo
  • 1,523
  • 9
  • 19
0

Thought of posting my solution here.

ECHO OFF
SET "JBOSS_DIR=C:\Work\jboss-as-7.1.1.Final"
SET "deployedAPP=MyApp.ear"
RMDIR /S /Q .\deploy
call mvn clean install -D build=P,JB
call mvn clean install -D build=F,JB
@echo | call %JBOSS_DIR%\bin\jboss-cli.bat --connect --controller=[mymachine_name]:9999 command=:shutdown
del /q %JBOSS_DIR%\standalone\deployments\*.*
xcopy /s /y .\deploy\function\Jboss\*.ear %JBOSS_DIR%\standalone\deployments
xcopy /s /y .\deploy\WorkFlowEngine\Jboss\*.ear %JBOSS_DIR%\standalone\deployments
cd %JBOSS_DIR%\bin
PING -n 61 -w 1 localhost >nul
START CMD /C CALL MyJboss.bat
SET count=0
:checkIfDeployed
    if exist "%JBOSS_DIR%\standalone\deployments\%deployedAPP%.deployed" (
        GOTO appDeployed
    )
    if exist "%JBOSS_DIR%\standalone\deployments\%deployedAPP%.failed" (
        GOTO deployFailed
    )
    PING -n 6 -w 1 localhost >nul
        GOTO checkIfDeployed
:appDeployed
    PAUSE
    EXIT
:deployFailed
    SET /A count+=1
    if %count% == 5 ( goto end )
    @echo | call %JBOSS_DIR%\bin\jboss-cli.bat --connect --controller=[mymachine_name]:9999 command=:shutdown
    PING -n 61 -w 1 localhost >nul
    START CMD /C CALL MyJboss.bat
    GOTO checkIfDeployed
:end
    PAUSE

Used the line

START CMD /C CALL MyJboss.bat

to start JBoss in another cmd window.Now all my codes from below will get executed.

Deepak Shajan
  • 911
  • 1
  • 7
  • 19