tags:

views:

345

answers:

3

I have a build process that creates an ear in a fairly complicated manner (multiple EJB jars, a couple of wars, a couple of sars (which are JBoss specific). The ant process for piecing this together is somewhat complex.

What is the best strategy to not recreate the creation logic of the ejb creation in ANT but still be able to deploy exploded to the application server or in an ear for QA and production.

Although I'm concerned about JBoss, the question is really relevant to any application server that supports exploded ear deployment, and is really more about ANT, how to avoid two different targets that recreated the logic of creating a zip file vs copying to a directory.

+1  A: 

An .ear file is a .zip file. To deploy an exploded version just unzip the contents into a folder named *.ear.

Chris Nava
I realize that. I am trying to reduce the time involved. I guess if the ear stays around between builds it isn't too bad, but it would be great to avoid the whole trip of adding to a zip to extract it.
Yishai
You could generate the build in a dependent target and and then <jar> or <copy> it using two others. This puts the logic to build the tree in one place and the logic to zip or copy it outside that process.
Chris Nava
I prefer to bite the bullet on unzipping the ear to ensure that the production servers have EXACTLY the same tree structure that I'm testing locally. IMHO, QA should be deployed EXACTLY like production so if one gets an exploded folder.ear they both should. You'll kick yourself when you suffer a bug (or worse an outage) in production due to an issue with file.ear vs. folder.ear.
Chris Nava
^^ YES. I have seen it happen. ;-)
Chris Nava
+3  A: 

I've found that what works best for us, is to create the ZIP/EAR/WAR/JAR contents in exploded form in the file system, and then as the final step zip/ear/war/jar it up to a file.

This allows us to have post processing steps which only knows of files and not zip-file entries, which is usually much simpler. If you work with an exploded deployment and a server which picks up changed files in the exploded deployment, you can simply use rsync to update only those files actually changed in the server deployment.

You would then have the building in one target, and packing in another, making it easy to do both.


See Alexander Pogrebnyak's answer in regards to how to handle manifests using this solution.

Thorbjørn Ravn Andersen
The thing is that the ANT jar/war/ear tasks have special handling for manifests. How do you deal with that?
Yishai
You create the Manifest.MF file manually and tell Ant to use that file when doing the jar/war/ear.
Thorbjørn Ravn Andersen
+2  A: 

This is in reply to your comment about manifest.

You should use <manifest> task (here is the link) to control manifest creation.

Here is the excerpt from my build file to supply manifest.

<copy toDir="${stage.dir}" flatten="true">
  <fileset dir="${resources.src.dir}">
    <include name="META-INF/MANIFEST.MF"/>
  </fileset>
</copy>

<manifest
  file="${stage.dir}/MANIFEST.MF"
  mode="update"
>
  <attribute name="Built-By" value="${builder.name}" />
</manifest>

<jar destfile="${project.jar.file}"
  basedir="${classes.dir}"
  manifest="${stage.dir}/MANIFEST.MF"
  duplicate="fail"
  whenmanifestonly="fail"      
/>

Pay attention to <manifest> task mode attribute. You always want to set it to update, otherwise <jar> task will always be running, as manifest will always be out-of-date.

Alexander Pogrebnyak
Cool, thanks! Very interesting.
Yishai