Using multiple profiles in Maven + Eclipse

2013-03-07 504 words 3 mins read

It’s possible that many of you already knew this but if not then here’ some basic info on Maven profiles. I have been using maven for over 2 and half years now, and have been copy pasting assembly and install files. I never bothered to know how Maven figures out how to read assembly and install file names. For example-

PROBLEM:

For all my projects I have been using assembly-jboss.xml to put the file/directory information and telling maven about my desired directory structure i.e. Pick files from a/b directory and put it in out directory c/d. The second file install-jboss.xml where I specify my panels, target files etc. It never occurred to me what happens if I change the file names to assembly-zzz.xml and intsall-zzz.xml.

Image 1

Well to cut the story short I checked out a fellow developer code on my machine and the command “mvn clean install” threw build error which said –

[1] [INFO] Searching for file location: C:Dineshworkspaceprov-ld-anin-trunkartifactssrcassemblyassembly-jboss4.xml

[2] [INFO] File: C:Dineshworkspaceprov-ld-anin-trunkartifactssrcassemblyassembly-jboss4.xml does not exist.

[3] [INFO] File: C:Dineshworkspaceprov-ld-anin-trunksrcassemblyassembly-jboss4.xml does not exist.

 

Now I was using IZPack plugin and always thought the assembly and install xmls are part of IZPack configuration, so for half an hour I was searching “IZPack assembly descriptor”. Needless to say I did not get any releveant search result. After scratching my head a little and doing a text search in Eclipse to figure out how am I telling maven to find the specific files (in my case the fellow developer had named them as assembly-wso2carbon40.xml and install-wso2carbon40.xml). No results.

SOLUTION:

In Maven you set up a profile in your .m2/settings.xml. For example my settings.xml looks like this


   
       
            jboss4
           
               
                1.5
                jboss4** 
**            

       

           

 

If you will notice I have specified that jboss4 tag has value jboss4. When maven is building your app, it looks for two files assemby-xxx.xml and install-xxx.xml. Here xxxin assembly-xxx.xml is the profile name. So in my case it looks in the settings.xml and sees that profile is jboss, so it uses to find a file assembly-jboss.xml and install-jboss4.xml.

So now the problem was that my developer friend had named the files as assembly-wso2Carbon40.xml and install-wso2Carbon40.xml. The first thing that came to my mind was let’s change the jboss4to ****wso2, that would resolve my issue. However I had other application where the file was named assembly-jboss.xml and install-jboss4.xml, which meant that my other application will error out on maven clean install and throw error message could not locate assembly file assembly-wso2Carbon40.xml .

Here’s comes the neat part, you can have multiple profiles in your settings file. So I updated my .m2/settings.xml


   
       
            jboss
           
               
               
               
                1.5
                jboss4
                C:Program Filesjboss-eap-4.3
                80
           

       

       
            wso2
           
                1.5
                wso2carbon40
           

       

   

 

Now when you build the project using Eclipse, just got to Run As ==> Maven Build …  and enter Goals = clean install and Profile = wso2

Image 4

 

That’s it!

 

~~Cheers!


author

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now