• Home
  • RSS Feed
  • Log in

Using the Maven2 assembly plug-in to package and deliver your applications
Posted by Okke Harsta at around evening time: July 30th, 2006

You have finished your first iteration in your project and in order to get feedback from the business you wish to have your application deployed on the test environment. In many projects the test environment is maintained by the developers. That is fine, but the acceptance and production environment are not. Why not start packaging and delivering your project artifacts like you would with a production release? This way you have a chance to fine-tune this process. When the time comes that you will have to deliver to an acceptance or production release you will have automated this process, aligned it with the expectations of the department responsible for deployment and, hopefully, made it less fallible. Where to start?

I'll be assuming in this blog that you use Maven2 for building the different parts of your Java application. If this is not the case I advise you to have a look at Maven2. With release 2.0.4 Maven2 has come to a maturity level that I feel I can safely recommend it to customers. Maven2 advocates one artifact for each project. A typical Java application has more than one sub-artifact: several jar files, a web archive and finally an ear file to package the lot. This typical setup is supported by Maven through the use of sub-modules. First you begin with a top level pom.xml where you define all the global configurations of your application. These normally would include things like:

  • The groupId.
  • The version.
  • An 'issueManagement' section
  • A 'ciManagement' section
  • Information about the developers
  • The configuration of the repositories (local and remote)
  • Source Control Management (scm) information
  • All the shared dependencies for all modules
  • 'distributionManagement' section including site information, your local company repository and snapshotRepository

The next thing to configure in your top pom.xml are the sub-modules of your project. The following xml fragment specifies that your application has five sub modules (oh, not the petshop again...):

<modules>
    <module>xebia-petshop-core-jar</module>
    <module>xebia-petshop-util-jar</module>
    <module>xebia-petshop-war</module>
    <module>xebia-petshop-statistices-war</module>
    <module>xebia-petshop-ear</module>
  </modules>

Good descriptive names of your sub-modules, including their artifact type, are always helpful and especially as their number grow. I have found it good practice to have the artifactId of a module equal the name of the module minus the type definition. Following this rule the artifactId name of the xebia-petshop-util-jar module would be xebia-petshop-util resulting in the artifact xebia-petshop-util-0.1-SNAPSHOT.jar. The pom.xml configuration of this sub-module would be something like this:

  <parent>
    <groupId>com.xebia.petshop</groupId>
    <artifactId>xebia-petshop</artifactId>
    <version>0.1-SNAPSHOT</version>
  </parent>
  <artifactId>xebia-petshop-util</artifactId>
  <packaging>jar</packaging>

Looking at the names of the sub-modules it is not too difficult to guess what the content would be. The xebia-petshop-core module has a dependency on the xebia-petshop-util module. The xebia-petshop-war module is dependent on the xebia-petshop-core module (this way the artifact of xebia-petshop-core will end up in the WEB-INF/lib directory of the xebia-petshop-0.1-SNAPSHOT.war. Finally the xebia-petshop-ear is dependent on the two war modules. The final deployable artifact is the xebia-petshop-0.1-SNAPSHOT.ear. I have found it also good practice to have an environment independent deployable artifact. So with this multi-module setup all the tests will be run and the -sub- artifacts will be created and deployed to your local and company repository when issuing the following Maven2 command:

$ mvn clean install deploy

Using the excellent Maven2 release plugin you can perform a release saving a lot of repetitive, manual work like updating the version, tagging the source code and deploying the artifacts to your repository. Now basically here should end your tasks as developer or not? The department or person responsible for deploying the
xebia-petshop-0.1-SNAPSHOT.ear probably needs additional information to succesfully deploy the application. For this reason we introduce a new module:

<module>xebia-petshop-dist</module>

The xebia-petshop-dist module will produce a tar archive including our ear and everything else needed for configuring the target environment. The choice of your application server of course has a significant impact on the required configuration. Let us assume that the IT department has developed a hardened configuration of the open source JBoss server. A hardened configuration of the JBoss server should at least address the following issues:

  • Securing the management console.
  • Securing the jmx console and jmx invoker.
  • Removal of the http invokers.
  • Removal of the default HsqDB datasource/database.
  • Configuration of the different security domains.
  • SSL enabling.
  • Removal of the download service.
  • Configuration of Log4J.
  • Configuration of the clustering capabilities.

It is out-of-scope to discuss in detail how to configure this. Based on a company specific configuration the developers of the xebia-petshop application must specify to the deployer which additional resources the application depends on. Let us assume that the application uses the following environment specific resources:

  • A DataSource configured in a xebia-petshop-ds.xml file.
  • Environment specific variables for configuring and injecting a Ldap server instance coded in a jndi.properties file.
  • SQL create scripts for the database schema and alternatively alter scripts for consecutive releases.

It is a matter of taste where to store these additional configuration files. Basically you will have to choose between the xebia-petshop-dist or xebia-petshop-ear module. Lets choose the second option and configure the pom.xml of the xebia-petshop-dist to use the assembly plug-in of Maven2 to build a tar archive including the ear file and the additional configuration files in order for the deployer to do his work:

 <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>attached</goal>
            </goals>
            <phase>package</phase>
          </execution>
        </executions>
        <configuration>
          <descriptor>src/main/assembly/dep.xml</descriptor>
        </configuration>
      </plugin>
   </plugins>
 </build>
 </build>
  <dependencies>
    <dependency>
      <groupId>com.xebia.petshop</groupId>
      <artifactId>xebia-petshop-ear</artifactId>
      <type>ear</type>
    </dependency>
  </dependencies>

The xebia-petshop-ds.xml and the jndi.properties files contains placeholders for the variables that need to be replaced by the deployer.

<datasources>
   <local-tx-datasource>
        <jndi-name>PetshopDS</jndi-name>
        <connection-url>@petshop.jdbc.url@</connection-url>
        <driver-class>com.mysql.jdbc.Driver</driver-class>
        <user-name>@petshop.jdbc.user@</user-name>
        <password>@petshop.jdbc.password@</password>
    </local-tx-datasource>
</datasources>

One additional file is necessary to include in our final archive: a README.html file that sums up the content of the archive and contains a list of all placeholders that need to replaced by the deployment team. The assembly plugin source file 'dep.xml' sums up all the content to be placed in the final archive.

<?xml version="1.0"?>
<assembly>
  <id>bin</id>
  <formats>
    <format>tar.gz</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>src/main/html/</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>README.html</include>
      </includes>
    </fileSet>
    <fileSet>
      <directory>../xebia-petshop-ear/src/jboss4x/deploy</directory>
      <outputDirectory>jboss/deploy</outputDirectory>
      <includes>
        <include>**/*.*</include>
      </includes>
    </fileSet>
    <fileSet>
      <directory>../xebia-petshop-ear/src/jboss4x/conf</directory>
      <outputDirectory>jboss/conf</outputDirectory>
      <includes>
        <include>**/*.*</include>
      </includes>
    </fileSet>
    <fileSet>
      <directory>../xebia-petshop-ear/src/main/sql</directory>
      <outputDirectory>db</outputDirectory>
      <includes>
        <include>**/*.*</include>
      </includes>
    </fileSet>
  </fileSets>
  <dependencySets>
    <dependencySet>
      <outputDirectory>/</outputDirectory>
      <unpack>false</unpack>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</assembly>

When the xebia-petshop-dist module is installed the xebia-petshop-dist-0.1-SNAPSHOT-bin.tar.gz will be uploaded to your local company maven2 repository where the deployer can pick it up and actually start his/their deployment procedure. One could even use the docbook plugin of Maven2 to generate the README.html based on a docbook xml source file.

Having an 'dist' module in your Maven2 project structure that uses the assembly plugin to archive all necessary resources and artifacts is a good step to a more controlled and automated release procedure.

  • Share/Bookmark

Filed under Java | 2 Comments »



2 Responses to “Using the Maven2 assembly plug-in to package and deliver your applications”



    Jan Says:
    Posted at: August 14, 2006 at 8:42 pm

    Altough 2.0.4 looks relatively stable – it is the multi module project reporting which is a real pain. Have you managed to set things up, so reporting – aggregated and not aggregated works for:

    – javadoc
    – jxr
    – surefire
    – changelog
    – changes
    – jdepend
    – cobertura
    – pmd
    – checkstyle



    Andrew Swan Says:
    Posted at: July 8, 2008 at 5:58 am

    Your blog software seems to have stripped all the XML tags out of your post; any chance you could re-post a corrected version please?



Leave a Reply

Click here to cancel reply.

Deployment automation for Java application running on Websphere, WebLogic and JBoss

Archives

  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009

Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India

Categories

  • Java (279)
  • Agile (109)
  • General (50)
  • Testing (42)
  • Performance (42)
  • Hibernate (36)
  • Scrum (33)
  • Podcast (31)
  • Architecture (31)
  • Spring (28)
  • SOA (24)
  • Maven (22)
  • Project Management (22)
  • Flex (17)
  • JPA (17)
    • JPA implementation patterns (13)
  • Eclipse (15)
  • Quality Assurance (14)
  • Middleware (19)
  • Frameworks (13)

Tag Cloud

    Xebia qcon Testing SOA fitnesse Groovy Java Maven Scala Closures Agile Agile Awareness Workshop Spring esb Grails IntelliJ Lean Functional Programming Hibernate Scrum Poppendieck Architecture Semantic Web JavaOne Ajax Performance XML product owner Seam Introduction to Agile
medicin depression buy phentermine without a perscription aricept generic hair loss help how do you prevent bone loss urinary tract infection symptoms viagra sex domination cialis viagra cures for throat infection buy sumycin acne care new medication for cancer treatment help for sleeping problems on-line pharmacies cure snoring medications to help clot blood what is aspirin buy zestoretic bronchitis vs pneumonia back pain muscle acne face medication muscle women pain behind knee fat blocker man health arthritis natural cure woman health women insomnia cheap phentermine online cats and irritable bowel syndrome buy cialis generic online nutritional diet for osteoporosis abnormal blood clots treatments for hair loss what is zyprexa dental whitening products impotence herbs drugs for diabetes allergy prevention buy canada levitra Mentax adhd in children hair loss in woman medicines for blood clot online imitrex viagra buy free dog products clindamycin drug how to stop hair loss chloramphenicol discount drug viagra what valium does permanent hair loss heart failure medicine avapro 150mg ordering viagra online food allergies order viagra online online viagra prescription carisoprodol mg improve your skin discount erectile dysfunction medication buy xanax online buy order viagra scabies teatments information allegra vitamine b1 diazepam breast cancer support free stop smoking cipro side effects ultram cheapest treatment attention deficit disorder discount vitamins supplements how to get viagra online synthroid buy cheapest cialis zyrtec online how to clear acne preventive osteoporosis immune stimulants what is hoodia On Line Viagra getting over the pain diflucan dosage health asthma online stores hair loss products blood clot drugs colon parasites hair loss products discount medicine pravastatin buy griseofulvin tablets order indomethacin dog health products how to take a beta-blocker diazapan is valium treating cold sores chronic pain drug what is osteoporosis stress drug tooth whitening lowering cholesterol naturally legality of buying cialis online order levitra treatment for insomnia cheapest cialis index depakote overdose alprazolam condom sales treatment of yeast infection xanax sales taking viagra after cialis how to control pain new birth control chest pain health prozac prescription blood clots viagra in mexico chlamydia pill cancer drugs cold flu drugs how do i order viagra online super viagra acyclovir medicine benadryl dosage erythromycin pregnancy buy contoured condom chronic muscle pain pet health dogs treatment attention deficit disorder dental teeth whitening asthma medicine free prescription drugs herpes drug diabetes treatment buy tooth whitening gel cheap fast valium generic levitra buy cheapest viagra online lopressor drug pharmacy drug prices ultram dosing treatments for bipolar disorder neurontin withdrawal parasite medication chlamydia tips for increasing breast size ways to enhance breast what is valium used for metformin tablet order birth control hair loss for men how does xanax work treatment hepatitis c rythmol cheap acai antioxidants nexium generic blood pressure pills levitra online no prescription Levitra Online medications on line motion sickness drugs bactrim online order roxithromycin nicotine where can i order viagra immune supplements buy erexin v bph prostate allopurinol xanax for depression drug new smoking stop cheap impotence drug generic cialis delivery new treatment for depression antibiotics for cat viagra china alternative medicine cholesterol viagra dose anxiety disorder treatment severe muscle pain treatment of cancer calcium carbonate penis enlargement without pill valium maximum dosage reasons for high blood pressure energy product breast enlargement info cheap effexor building your body wrinkle cream aricept dosage alpha blocker increasing female sex drive valium depression new pain meds no rx xanax drug trileptal mg imitrex avapro 150mg medicine drugs contraception female claritin pill medication for acne med orders buy viagra internet levitra effect treatment for blood clots order sominex buy creatine buy precose cheap viagra overnight lopressor drug body building info health drugs general health and medical what is diazepam eye infections in dogs online prescription pills diclofenac tablet new medication anxiety buy citalopram medication male enhancement enhancement fat blocker medicine for throat infection order cardizem about soma health remedies for dogs generic xanax cheap zyrtec for depression medicine viagra sex domination buy acne skin care product hypnosis help study cure vaginal yeast infection weight loss supplement program muscle pain in leg how to increase erection buy viagra what is cla augmentin doses gaining muscle mass health med online heart rate treatments lopressor drug dog ear canal phentermine without prescription viagra order online weight loss glipizide diabetes astelin generic fat blocker buy gel tooth whitening cheap wellbutrin online weight loss program buy antiox anti-biotics acne skin treatmen tramadole vpxl pill drugs affecting levitra immune system support augmentin hypothyroidism medication buy erexin v uy prescription medication without a prescription buy discount order osteo arthritis online buy pilocarpine cheapest place to buy phentermine parasite treatment impotence help body fat loss viagra herb alternative constipation supplements treatment dementia adhd and medications muscle spasm relief viagra online cheap relieve upper back pain stop hair loss discount viagra online menstrual cycle problems antifungal shampoo side effects ativan gabapentin medication where can i buy viagra diazepam buy soma online clonidine dosage viagra gel top hair loss fast antibiotics cure chlamydia skin fungal infections drug zofran give up smoking alternative medicine cholesterol sleeping help best online viagra scams prednisone 10mg viagra sex domination lotensin easy weight loss pain meds without prescription over the counter drugs new high blood pressure medic generic compazine cetirizine drug order phentermine best fat blockers woman enhancement supplement drug zofran buy precose new drug treatment for cancer how to increase fertility viagra in australia benadryl dosing buy alcoholism medications order l arginine buy diazepam generic for ativan ativan prescription drugs weight loss treatment for chest pain woman health where can i buy phentermine online skin fungal infection give up smoking viagra on line hoodia information how does osteoporosis occur buy viagra online buy alcoholism medications depakote overdose klonopin pill tetracycline capsules what is high blood pressure bladder control for dogs generic for lipitor glucophage online pharmacy gabapentin dosage treating yeast infections dog health info cymbalta anxiety cheap tramadol without prescription hydrea drugs used for cancer cure for high blood pressure alcohol and valium relief from constipation liver infection treatment cialis soft zantac medication help sleep problems all natural antibiotics order medication without prescription sleep problems free hypnotherapy gaining muscle mass cheap viagra order online natural help for pain how to buy viagra drug price celebrex information otc diuretic levitra 10 mg buy medicine online pets products relief foot pain cialis without prescription med care cheapest generic cialis rapid hair loss pain medications generic side effects meds without prescriptions cat anxiety buy simplicef natural cure arthritis effects of high blood pressure lowest price generic viagra how to get birth control new breast cancer drug buy topamax blood pressure meds when are beta blockers prescribed how to get pain meds order fosamax online viagra name order viagra viagra cialis cat's eye health how to relieve lower back pain treating ear infections diazapan is valium online pain doctors high blood pressure in elderly medication to stop smoking wellbutrin dosages diabetes blood sugar levels weight loss diet pill side effects of prescribed pain pills drug list high blood pressure buy cialis online in usa ultram cost how to help osteoporosis how to use clomid discount brand viagra wellbutrin cymbalta buy pills without a prescription buy pain medicine online tab tramadol depression symptoms treatment how levitra work hypertension medications beta blockers prevent premature ejaculation xanax interactions with other medicines purchase medicine on line does alli work xenical mexico prescriptions buy sumycin uy prescription medication without a prescription ambien cost methocarbamol effects cheap beta blockers cats bladder reduce cholesterol naturally metformin tablet scabies medicine breast enhancer pills body building over 50 order viagra cheap zestril medication how to buy prescription medications online pharma kamagra drugs depression ear infection symptoms big muscle controlling blood pressure pain meds and pregnancy buy diazepam without prescription skin allergies antibiotic zoloft buy weight loss nutrition program Buy Cialis breast increase meds without prescriptions blood clots medical edema treatment for flu best hangover remedy diabetes drugs