5 Replies Latest reply on Apr 2, 2008 11:31 AM by jaikiran pai

    Automatic deploy with MainDeployer

    Jiri Frydek Newbie

      Hi all,
      I'm deploying my application from script, which is using MainDeployer. All works properly, but deploy is not permanent. After JBoss restart I must deploy application again. It is bug, feature of wrong setting or usage.
      Many thanks.

      Jefec

        • 1. Re: Automatic deploy with MainDeployer
          jaikiran pai Master

          From what i remember, the MainDeployer deploys the application in %JBOSS_HOME%/server/< serverName>/tmp folder. This tmp folder gets cleaned up on restarts.

          The last time, when i was playing around with a similar requirement on a sample application, i had deployed my own service using a *-service.xml (which extends MainDeployer) and overriden the deploy method as follows:

          
          public class ExtendedMainDeployer extends MainDeployer {
          
           /**
           * Logger
           */
           protected Logger log = Logger.getLogger(this.getClass().getName());
          
           /**
           *
           */
           public void deploy(URL url) throws DeploymentException {
           String serverDeployFolderPath = System.getProperty("jboss.server.home.dir") + "/deploy/";
           File file = new File(url.getFile());
          
          
           //just copy it to server deploy folder and let the deployer pick it up
           try {
           log.info("Copying " + file.getName() + " to " + serverDeployFolderPath + file.getName());
           copy(url,new File(serverDeployFolderPath + file.getName()));
           } catch (IOException ioe) {
           log.error("Could not copy " + url.getFile() + " to " + serverDeployFolderPath, ioe);
           throw new DeploymentException(ioe);
           }
           }
          
          }


          All this piece of code does is it copies the application to the "deploy" folder of JBoss so that the server picks it up for deployment. This way, you dont have to worry about restarts. I am not sure whether this is an option for you, though.

          Maybe someone has better ideas?



          • 2. Re: Automatic deploy with MainDeployer
            jaikiran pai Master

             

            "jaikiran" wrote:

            All this piece of code does is it copies the application to the "deploy" folder of JBoss so that the server picks it up for deployment.


            On second thoughts, this is tricky. If the "copy" does not complete before the next scan cycle of the deployment scanner (probably because the application is a large file), then the deployer will pick up an incomplete deployment and will throw errors.

            I'm deploying my application from script, which is using MainDeployer.


            Any specific reasons for doing this? Also, which version of JBoss?

            • 3. Re: Automatic deploy with MainDeployer
              Jiri Frydek Newbie

               


              Any specific reasons for doing this? Also, which version of JBoss?


              Because it is requirement from our product management :). We are using JBoss 4.2.2

              Previously we are using Glassfish and we had created autodeployment in ant.
              Now we need the same tool for permanent deployment for JBoss.

              Using of MainDeployer is not reqired, but I don't find any other solution (expect copying to deploy directory).

              • 4. Re: Automatic deploy with MainDeployer
                jaikiran pai Master

                 

                "jefec" wrote:

                Using of MainDeployer is not reqired, but I don't find any other solution (expect copying to deploy directory).


                In that case, copying to the deploy directory is probably a better solution. As i mentioned in my earlier post, all you have to worry about with this approach is to ensure that the "copy" operation completes before the file is picked up for deployment. I do see a way of getting around this, JBoss by default ignores files ending with .bak extension (as well as some other extensions which you will find mentioned in the server/< serverName>/conf/jboss-service.xml file) from deployment. What you could do is while copying your application (ex: myApp.ear) to the deploy folder, copy it as myApp.ear.bak. Once the copy operation completes, just rename it to myApp.ear. This way, even if the deployment scanner starts scanning the deploy folder when the copy operation is in progress, its wont pick up this file. The file will be picked up only after the rename operation is done (which wont take any time).

                Would this approach work for you?

                • 5. Re: Automatic deploy with MainDeployer
                  jaikiran pai Master

                   

                  "jaikiran" wrote:
                  As i mentioned in my earlier post, all you have to worry about with this approach is to ensure that the "copy" operation completes before the file is picked up for deployment.


                  Oh, by the way, this applies only if you are deploying the application when the server is started. If the server is not started and your are copying your application to the deploy folder then you don't have to worry about this case.

                  "jaikiran" wrote:

                  In that case, copying to the deploy directory is probably a better solution.


                  One more reason why this approach might be better is, you don't need the server to be started when you are running your build (for copying to the deploy folder). In the MainDeployer approach, you need the server to be up to call the MBean.