6 Replies Latest reply on Jul 21, 2011 10:34 AM by peterj

    How to include a script during deployment phase

    chogall

      Hi all!

       

      I am new to JBoss and am currently using JBoss 6.0.0.

       

      What I want to do is the following:

       

      I need to deploy a WAR file on JBoss and that will be done on Windows machines as well as on Linux machines. The thing is, in this WAR file, there is a XML file which contains some path lines. And in order for the web application to correctly work, these path lines need to be changed depending if it will be run on a Windows machine or a Linux machine.

      So my idea is to somehow include a script in JBoss at the time I load my WAR File (so that I can deploy it), and I would like this script to detect if the actual machine is a Windows or Linux one and therefore operate the necessary changes in the XML file, and then deploy the WAR file.

       

      Would anyone know if my idea is realizable first ? And if yes, any tips about how to proceed ? Like, where should the script be included ? Or maybe I should not write a separate script but modify an existing JAVA file for instance ? Any tips or comments are welcome!

       

      If I haven't been clear enough or if you need additional information, please let me know.

       

      Thank you in advance!

       

      sam

        • 1. Re: How to include a script during deployment phase
          peterj

          Here are a few suggestions.

           

          a) Use a path that contains '/' as directory separators and don't specify a drive letter. For example, if the path is "/data/webapp/config.properties", then that is the exact location used on Linux and on Windows that path is interpreted as being on the current disk drive (for example, at c:\data\webapp\config.properties). I use this mechanism all the time. The nicest thing about it is that it works even if on Windows I am used a different disk drive. For example, on my laptops I have everything on the C: drive but on my desktops I work on either the F: drive or the D: drive. Using a drive-less path lets me use the exact same code/scripts/files on all of my PCs, Windows and LInux, without having to change anything.

           

          b) Define two properties, one for each system. For example, linux.location=xxx and windows.location=yyy. Then in your code determine if you are running Linux or Windows and based on that pick the correct property. I also use this mechanism occasionally. (I know this mechanism isn't a perfect fit for your situation, but perhaps it will spark an idea...)

          • 2. Re: How to include a script during deployment phase
            chogall

            Hi Peter,

             

            Thank for your reply!

            Basically, the path on windows is C:\temp\blabla and that on linux is /usr/local/lib64.

             

            My XML line was :

            <Property name="folder" value="C:\temp\blabla" />

             

            and following what you explained in a), I changed it to :

             

            <Property name="folder" value="/temp/blabla" />

             

            and it works well!

            Actually the path on Linux can't be changed, it has to remain /usr/local/lib64. So it means that I should change the one on Windows to C:\usr\local\lib64 as well ? With your solution in a), both should be the same, right ?

             

             

            Meanwhile, I thought about another possible solution: to include both paths in the value field. Something like:

             

            <Property name="folder" value="C:\temp\blabla;usr/local/lib64" />

             

            I thought it could pick only the path that works but it doesn't. Maybe because this is in a string and that later this value will be inserted in a java program as a String value I guess...

             

             

            In regards to your solution in b), does XML allow you to have control loops (if-statements) ? or should I use something like XSLT ?

             

            Thank you!

            • 3. Re: How to include a script during deployment phase
              peterj

              >>With your solution in a), both should be the same, right ?

              Correct, the file should be in the same location on both machines. (All of my Windows machines have an /opt directory for this reason...)

               

              >>I thought it could pick only the path that works but it doesn't.

              This could actually work - you code would get both paths which you could then split via String.split() and choose the appropriate value.

               

              Another alternative:

              <Property name="win.folder" value="C:\temp\blabla" />

              <Property name="linux.folder" value="/usr/local/lib64" />

               

              Then have your code pick the appropriate value based on the OS.

              • 4. Re: How to include a script during deployment phase
                chogall

                Ok thank you very much for these tips! Really helped!

                • 5. Re: How to include a script during deployment phase
                  chogall

                  Hi again,

                   

                  b) Define two properties, one for each system. For example, linux.location=xxx and windows.location=yyy. Then in your code determine if you are running Linux or Windows and based on that pick the correct property. I also use this mechanism occasionally. (I know this mechanism isn't a perfect fit for your situation, but perhaps it will spark an idea...)

                  Is it possible to test the operating system inside an XML file ? Because it seems it's not possible, am I correct ? Let's say I would like to include a script inside my WAR file (shell script, or even a JAVA file) that would be responsible to test which OS the machine is running on and choose the right "Property". How should I tell JBoss that it should execute that particular script first ? Or is there a better way of doing this ?

                   

                  Thanks!

                  • 6. Re: How to include a script during deployment phase
                    peterj

                    The decision between the two values is done within your Java code. Neither XML nor JBoss AS will do this for you.