Discussions

News: Fully Automate Build & Deployment using Ant

  1. Fully Automate Build & Deployment using Ant (17 messages)

    The technologies involved Ant, CVS, and WebSphere. The scenario is you run the scripts from your pc client and it will do the build in your pc, distribute the artifacts to a remote Unix environment, deploy the artifacts in Unix, and install the war application in WebSphere. You can optionally backout the entire installation. This is a complete working set of scripts. You can copy/paste the scripts literally or modify the application via properties to suit your needs. The following files are used: 1. main.xml 2. build.xml 3. dist.xml 4. deploy.xml 5. install.xml 6. project.properties 7. deploy.properties To execute, the first and the only step is: ant -buildfile main.xml The following shows the complete listing of the files: ======================================================= main.xml ======================================================= <?xml version="1.0"?> <!-- Ludwin Barbin 2009-07-24 --> <!-- Main delegator --> <!-- Build application --> <!-- Full deploy application --> <!-- Distribute Files --> <!-- Backup Files --> <!-- Deploy Files --> <!-- Install application to WebSphere --> <!-- Cleanup Files --> <!-- Backout Files if deployment fails --> ========================================================== build.xml ========================================================== <?xml version="1.0"?> <!-- Ludwin Barbin 2009-07-24 --> <!-- call the build steps --> <!-- package war file --> <!-- package web files --> <!-- package was files --> ======================================================= dist.xml ======================================================= <?xml version="1.0"?> <!-- Ludwin Barbin 2009-07-24 --> <!-- create temp directory for distribution --> <!-- create temp directory for distribution --> ========================================================= deploy.xml ========================================================= <?xml version="1.0"?> <!-- Ludwin Barbin 2009-07-24 --> ========================================================== install.xml ========================================================== <?xml version="1.0"?> <!-- Ludwin Barbin 2009-07-24 --> <!-- WebSphere tasks --> <!-- delegator --> ------------------------------------------------------- project.properties ------------------------------------------------------- # Ludwin Barbin 2009-07-24 # === CVS properties ================================ main.project =myproject cvs.root =:pserver:anonymous:anonymous at my dot cvs dot com:/myrepository # === directories ================================== lib.dir =${basedir}/lib src.dir =${basedir}/src classes.dir =${basedir}/classes build.dir =${basedir}/build web.dir =${src.dir}/${main.project}/WebContent web.root.dir =${src.dir}/${main.project}/web_root was.root.dir =${src.dir}/${main.project}/was_root # === archive filenames =============================== app.war =app.war app.web.tar =app-web.tar app.was.tar =app-was.tar app.web.bkup.tar =app-web-bkup-${DSTAMP}.tar app.was.bkup.tar =app-was-bkup-${DSTAMP}.tar app.bkup.ear =app-bkup-${DSTAMP}.ear ------------------------------------------------------- deploy.properties ------------------------------------------------------- # Ludwin Barbin 2009-07-24 # ============= UNIX directories ================= # In Web web.app.dir =/apps/myapp web.archive.dir =/apps/myapp-archive web.tmp.dir =${web.archive.dir}/tmp # In WAS was.app.dir =/apps/myapp was.archive.dir =/apps/myapp-archive was.tmp.dir =${was.archive.dir}/tmp was.bin.dir =/apps/WebSphere/bin # ============= Login properties ================= web.host =mywebhost web.userId =webid web.password =web123 was.host =mywashost was.userId =wasid was.password =was123 # ============= Ant execution properties ================= web.ant.deploy =ant -buildfile ${web.tmp.dir}/deploy.xml was.ant.deploy =ant -buildfile ${was.tmp.dir}/deploy.xml was.ant.install =sudo -s ${was.bin.dir}/ws_ant.sh -buildfile ${was.tmp.dir}/install.xml web.ant.version =ant -version was.ant.version =ant -version was.wsant.version =${was.bin.dir}/ws_ant.sh -version # === WebSphere server properties =============================== was.cell =mywascell was.node =mywasnode was.server =mywasserver # ================ Installation options properties ======================== app.name =myapp context.root =/myapp was.install.options =-cell ${was.cell} -node ${was.node} -server ${was.server} -contextroot ${context.root} -appname ${app.name} -- End of files -- Feel free to use the code in your project. This is especially useful in Development environment where a quick deployment is essential. The benefits of having an automated build & deployment is very applicable when using Agile development. It allows you quickly see your changes, get feedback, and adapt accordingly. If you have a way of improving the code, let me know. I am not an expert in Ant but I've used the above scripts in my projects and it helped our development team a lot.

    Threaded Messages (17)

  2. It is nice to see that someone lists a piece of code, that we all coded about 5-10 years ago before modern lifecycle tools were available. Maybe a look at something like maven (I am talking about lifecycle management and not dependency management ) would be advisable. Ant is somewhat outdated nowadays in this usage pattern.
  3. Says...[ Go to top ]

    ...someone who is using a build system that in any other community than the Java one would cause a reaction along the lines of "what the hell is this?" Maven is possibly the worst piece of software I've ever had the non-pleasure of using. Two full years I had to endure the pain. The horror...
  4. Re: Says...[ Go to top ]

    ...someone who is using a build system that in any other community than the Java one would cause a reaction along the lines of "what the hell is this?"

    Maven is possibly the worst piece of software I've ever had the non-pleasure of using. Two full years I had to endure the pain. The horror...
    I am in the java community and I did initially just say that. While it is nice to see the entire code, but this brings back memories of having an entire application in one file or just one do-all class. Apart from tools like maven, we should be looking at CI tools, Cruise Control, Continuum, Hudson, TeamMate etc can help a lot in this.
  5. Re: Says...[ Go to top ]

    maven 1.0 was hell. i like ant too. but having had to dig through some absolutely unintelligible builds with ant, maven 2.x has grown a lot on me. although i really would like to see improvements to nested project structures, and it drives me crazy having to have an application running to host jar files (hello javax.*).
  6. Re: Says...[ Go to top ]

    Yes, it is quite funny to see posts like this nowaways (when Maven is the mainstream tool). Still, I am using using ant+ivy with a customer. We have common build scripts, that are used in projects (and distributed via ivy). A project build script is generally then very simple, about 50 lines. We have all the control for builds in our hands. Time spent on maintaining common ant scripts is not much, probably less than struggling with Maven to support our project structure. Creating clean ant scripts is actually easy and fast(think about the time spent on project code). Of course, this is not very sexy in 2009, but it works.
  7. Re: Says...[ Go to top ]

    If you are struggle every time with your project structure, you have not understand maven. make your pom.xml (build file) once. Then create something like an Archetype (look it up :):) and then do not ever worry about your project structure, but be awed :):) by the power of our god maven :):) (a bit joking with you and ridiculing maven)
  8. Re: Says...[ Go to top ]

    If you are struggle every time with your project structure, you have not understand maven.
    Don't get me wrong. We are not struggling with Maven with every project. For a customer, we once evaluated it (when buggy 2.0 was just out), but it didn't make sense to switch to it. We resolved dependency management with Ivy and stick to our current ant scripts. It worked and still works fine. For another customer, Maven is used with its goods and bads. What I'm saying is that there is still not ultimate build tool, that I could happily recommend for all environments. But I would hope that tool will be something like Gradle instead of Maven. If Maven works in all cases for you, then use it. I won't.
  9. Hello Gentlemen Maven has very right idea of artifacts, transitive dependencies and repositories. POM shines as a descriptor of artifact's dependencies. Unfortunately as a build system maven has lot of drawbacks. Most questionnable is pollution of POM with plugin-specific details, which leads to bloated poms, and actually has no any relation to dependency resolution. Moreover, maven support is very terrific as compared to ant, there's no single place in internet to collect useful information about maven plugins, lot of them are still of alpha/beta quality. Moreover, maven support in IDEs (at least eclipse plugin I tried), is far not as convenient to use as ant support. We in our company use very satisfactory solution, which uses ant (reusable modular build files for build) and maven (using maven ant tasks) for dependency resolution and artifact tracking. Our typical project build system consists of conventional directory structure (similar to maven, but easier), pom file containing dependency information only, one build file which overrides and declares dependencies to standard ant tasks located in reusable build files. Thats all. In fact this is quite similar to ivy, but easier, because it does not require ivy file in addition to pom. btw Phil, thank you for pointing to gant/buildr, I think scripting could really bring benefits to build systems, at leas maybe DSLs based on scripting languages. I though see some mismatch between procedural approach provided by scripting languages and declarative approach used in most build systems I know (make, ant, maven..) Regards, Dmitry V. Zemnitskiy, CEO, pragmasoft.com.ua
  10. Entropy kills....[ Go to top ]

    ...never forget - A tool is only worth using if the effort of learning and supporting a new technolody plus the new problems it creates are outweighs its disadvantages....Strangely the "Keep Things Simple" Evangelists gave us some of the most cumbersome tools like Maven with its incredible inflexibility, XML Configuration Hell and Annotation Spaghetti with DI Tools and so on....
  11. Re: Entropy kills....[ Go to top ]

    Maven is all about keep it simple. a simple pom (and if you do not know how to handle xml then you have all kinds of problems these days) With next to no code in it what so ever. And you can build test compile package deploy etc.. For a simple java app. about 10 lines of code in my pom. And I can do alot (compile/test/package/install/deploy/documentation/site). With ant I need the hell script in this article to do the same. ivy.. euuuhh thats no build tool. Only a small part of the solution. There is no strict structure in maven, just a SUGGESTED one. You can define whatever structure you like and tell maven how to handle it, just like you need to tell ant how to handle your structure. I have build lots of projects is it single project or multiproject, weird folder structures, Flex projects with java. Big and small. Any place that I see that uses ant it is a xml hell. scripts break (because it is c/p from project to project). To complex too understand etc. Where maven is used, initially some resistance, but when they see how easy it it to use, they do not want anything else. If you have a project structure that is weird/complex/out of the ordinary, you should start thinking if you did not build your system overly complex. But I like just to put my effort in creating business code and keep my customer happy, while you type and debug your ant script which is of no use to the customer :):)
  12. Re: Entropy kills....[ Go to top ]

    Maven is not in any way about keeping it simple. Maven is about someone getting the idea "hey, I can pull things automatically of the Internet" a long long time ago. A build system that has a default folder structure that is "src/main/java" has obviously never worked in the real world.
  13. Re: Entropy kills....[ Go to top ]

    A build system that has a default folder structure that is "src/main/java" has obviously never worked in the real world.
    For me it works every time. With Ant I had to read someone's "clever" ideas of how project should be organized and built. With Maven I just type mvn source:jar install eclipse:m2eclipse and it works. Just look at some Apache projects... Sure there are some quirks when you have non-standard project organization - with Ant there are always quirks. And one more thing - there is a myth with products advertising themsleves as "start in 10 minutes" - this slogan is really catchy for non-experienced developers. I don't want to start in 10 minutes - I want to change something in 10 minutes 2 years (or even 2 months) after project's start...
  14. Re:[ Go to top ]

    The meaning was meant to be: "Someone developing a build system that has a default folder structure that is "src/main/java" and think that is normal has obviously never worked in the real world."
  15. Re: Entropy kills....[ Go to top ]

    Maven is all about keep it simple.
    For a simple java app. about 10 lines of code in my pom.
    That's true. But in long term or more complex project 10 lines are not enough. Maven for me looks like a candy for child - at first it looks very sexy, it does everything for you with ~10 lines of pom file. You are involved and happy for a while. But when your needs grow, when you want to do more complex actions (automatically create distros, tag/copy versions in Subversion) then you are really getting into troubles. OK - there are plugins. But all we know how they work. If something doesn't work - it's your problem. In one medium project (containing >10 subprojects) we used Maven for ~2 years. During that time we spent about 2 weeks fighting with Maven (every 'change' took about 2-3 days to complete). And finally we moved to Ant+Ivy (we did it 2 days). In result we have clear, permanent build system, build scripts contains less code, build process completes in several seconds (in Maven it took several times longer). So my opinion is: Maven is OK for startup, demo tool, some simple open source project. But for real projects it's better to avoid it.
  16. dead god. ever hear of a scripting language? check out gradle/gant or buildr. please.
  17. dead god. ever hear of a scripting language?

    check out gradle/gant or buildr. please.
    huh? if the solution works for the original poster, then it works for them. projecting your own preferences on someone else is really not helpful.
  18. The best build system[ Go to top ]

    dead god. ever hear of a scripting language?

    check out gradle/gant or buildr. please.
    If it is the better build environment, you could show us your build system based on gradle/gant or buildr. That us give it a try.