P0w3rK!d has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I am performing development in Java/XML/Perl and would like to know if my fellow monks have performed any builds with ANT in conjunction with Perl? I am just getting my feet wet with ANT and I am curious as to what you have done, what pitfalls you have encountered, along with any tips and tricks and/or resources where Perl is concerned.
Thank you :)

-P0w3rK!d

Replies are listed 'Best First'.
Re: Ant and Perl
by coreolyn (Parson) on May 29, 2002 at 18:01 UTC

    By putting a Perl front end to calling ANT builds I've managed to carve out a significant niche in the build/deploy process for Perl. Perl takes care of file movement and modifications and then sets up environment vars to control the build. This allows for multiple applications to utilize a centralized set of ANT targets so that each new app that comes up can work off a template of pre-set task to build their application.

    For instance Perl sets up $ENV{APPNAME} with the appropriate value that it has parsed from a text configuration file and than executes the build.xml for that application. The ant file can pick up that value via a line <property name="appname" value="${env.APPNAME}"/> ANT can then access that value as ${appname}

    Tip try to keep all required OS calls isolated to one area and executed from the Perl Code. Don't just use backticks but create functions that are reusable and cross platform as most development happens on NT but production may be a Unix variant

    Modularity and reuse is key as while this project started as just a one-time quick fix and has grown into an integral part of the infrastructure with non-stop feature creep for over a year now. (There's already quite a list of new feature request for Version 3).

    One place where Perl has stood out has been in Pre and Post Deployment modifications to files ( to make server/environment specific changes to files ) and in pushing directories between servers in shared environments

    Best of luck.

    coreolyn
      Thank you for your feedback. I am writing this up for several platforms and will use your suggestions :)
Re: Ant and Perl
by lachoy (Parson) on May 29, 2002 at 17:14 UTC

    I'd be surprised if you found any resources regarding Perl and Ant. The existing framework for building/testing/distributing Perl modules is fairly well-documented and ubiquitous, and most Perl projects use make if they need something more.

    Running Perl scripts from Ant just requires the exec task, and the only thing to note is that the executable is the perl binary and your script is the first argument, like:

    <target name="generate_session_descriptor" depends="init" description="Descriptor fragments for a session bean"> <exec executable="perl"> <arg value="${generate}/generate_session_descriptors.pl"/> <arg value="-d ${meta-inf}"/> <arg value="-n ${bean_name}"/> <arg value="-r ${bean_name}"/> <arg value="-h ${bean_name}Home"/> </exec> </target>

    Hope this helps.

    Chris
    M-x auto-bs-mode

      Hello,

      Description:

      I'll be building new Java classes for everything else I need to implement. I've already build one class and was able to reference it through ANT. However, there are several Perl scripts I need to launch. I have been unable to get this simple example to work. Is there some trick to getting the CLI options to the perl script you are executing?

      Code:

      <?xml version="1.0"?> <project name="projectfoo" default="targetfoo" basedir="."> <description> Ant+Perl test </description> <target name="targetfoo" description="launch perl script"> <exec executable="perl"> <arg value="c:\mydir\foo.pl"/> <arg value="-f c:\xyz\filename.txt"/> </exec> </target> </project>
      I get the following error:

      Output:

      Build sequence for target `projectfoo' is targetfoo Complete build sequence is targetfoo

      test2:
           exec Current OS is Windows 2000
           exec Executing 'perl' with arguments:
           exec 'foo.pl'
           exec The ' characters around the executable and arguments are
           exec not part of the command.
      

      Thank you :)
      -P0w3rK!d

        The fact that the argument regurgitation says foo.pl instead of c:\mydir\foo.pl is a red-flag that some interpolation is going on. Try c:/mydir/foo.pl or c:\\mydir\\foo.pl. Likewise with the other argument.

        Chris
        M-x auto-bs-mode