2 Replies Latest reply on Jan 27, 2010 7:14 PM by Arbi Sookazian

    ant build script for Weld examples

    Arbi Sookazian Master

      So I was reading the CDI refcard on Javalobby and noticed this in the build.xml:


      <macrodef name="maven">
                <attribute name="target" />
                <attribute name="basedir" />
                <element name="args" implicit="true" optional="true" />
                <sequential>
                     <java classname="org.codehaus.classworlds.Launcher" fork="true" dir="@{basedir}" failonerror="true">
                          <classpath>
                               <fileset dir="${maven.dir}/boot">
                                    <include name="*.jar" />
                               </fileset>
                               <fileset dir="${maven.dir}/bin">
                                    <include name="*.*" />
                               </fileset>
                          </classpath>
                          <sysproperty key="classworlds.conf" value="${maven.dir}/bin/m2.conf" />
                          <sysproperty key="maven.home" value="${maven.dir}" />
                          <args />
                          <arg line="@{target}" />
                     </java>
                </sequential>
           </macrodef>



      How does this work?  And yes, I did read this: http://ant.apache.org/manual/CoreTasks/macrodef.html but still don't get it.


      Is the ant script a hook into the mvn install/deploy?  plus target for moving the file to app server?

        • 1. Re: ant build script for Weld examples
          Pete Muir Master

          It's a macro for launching Maven from an ant build where you can do


          <maven target="clean install" />

          • 2. Re: ant build script for Weld examples
            Arbi Sookazian Master

            Ok, cool.  I have a functional build.xml for my Seam 2.1.1.GA EAR project so now I can do hot deployment of facelets via an explode target similar to what we have in seam-gen.  Thanks!


            Here are the targets of interest:


            <target name="explode" depends="clean, package, unzip">
                      <mkdir dir="${jboss.home}/server/${jboss.profile}/deploy/${ear.app.name}.ear" />
                      <copy todir="${jboss.home}/server/${jboss.profile}/deploy/${ear.app.name}.ear">
                           <fileset dir="${artifact.dir}" />
                      </copy>
                      <echo message="The app can be accessed at ${final.url}" />
                 </target>
                 
                 <target name="explodeonly">
                      <copy todir="${jboss.home}/server/${jboss.profile}/deploy/${ear.app.name}.ear/${war.app.name}.war/restricted/billing">
                           <fileset refid="war.billing.view" />               
                      </copy>
                      <copy todir="${jboss.home}/server/${jboss.profile}/deploy/${ear.app.name}.ear/${war.app.name}.war/restricted/merchant">
                           <fileset refid="war.merchant.view" />               
                      </copy>
                      <copy todir="${jboss.home}/server/${jboss.profile}/deploy/${ear.app.name}.ear/${war.app.name}.war/restricted/assessment">
                           <fileset refid="war.assessment.view" />               
                      </copy>
                      <echo message="The app can be accessed at ${final.url}" />
                 </target>
            
            <target name="unzip">
                      <echo message="Base directory is ${basedir}" />     
                      <mkdir dir="${basedir}\com.echo.cis.gui.ear\target\${ear.app.name}\temp"/>
                      <unzip src="${basedir}\com.echo.cis.gui.ear\target\${ear.app.name}\${war.app.name}.war" dest="${basedir}\temp"/>
                      <delete file="${basedir}\com.echo.cis.gui.ear\target\${ear.app.name}\${war.app.name}.war"/>
                      <mkdir dir="${basedir}\com.echo.cis.gui.ear\target\${ear.app.name}\${war.app.name}.war"/>
                      <copy todir="${basedir}\com.echo.cis.gui.ear\target\${ear.app.name}\${war.app.name}.war">
                           <fileset dir="${basedir}\com.echo.cis.gui.ear\target\${ear.app.name}\temp" />
                      </copy>
                      <delete dir="${basedir}\com.echo.cis.gui.ear\target\${ear.app.name}\temp"/>
                 </target>
                 
                 <target name="package">
                      <maven target="install" basedir="${basedir}">
                           <arg line="-f ${pom.file}" />
                      </maven>
                 </target>
            
                 <target name="clean">
                      <echo message="Deleting ${basedir}\com.echo.cis.gui.ear\target\${ear.app.name}\temp directory"/>
                      <delete dir="${basedir}\com.echo.cis.gui.ear\target\${ear.app.name}\temp"/>
                      <maven target="clean" basedir="${basedir}">
                       <arg line="-f ${pom.file}" />
                      </maven>
                 </target>
            
            <target name="unexplode" description="Undeploy the exploded archive">
                      <delete failonerror="no">
                           <fileset dir="${jboss.home}/server/${jboss.profile}/deploy/${ear.app.name}.ear">
                                <exclude name="**/*.jar" />
                           </fileset>
                      </delete>               
                      <delete dir="${jboss.home}/server/${jboss.profile}/deploy/${ear.app.name}.ear" failonerror="no" />          
                 </target>
            
            <macrodef name="maven">
                      <attribute name="target" />
                      <attribute name="basedir" />
                      <element name="args" implicit="true" optional="true" />
                      <sequential>
                           <java classname="org.codehaus.classworlds.Launcher" fork="true" dir="@{basedir}" failonerror="true">
                                <classpath>
                                     <fileset dir="${maven.dir}/boot">
                                          <include name="*.jar" />
                                     </fileset>
                                     <fileset dir="${maven.dir}/bin">
                                          <include name="*.*" />
                                     </fileset>
                                </classpath>
                                <sysproperty key="classworlds.conf" value="${maven.dir}/bin/m2.conf" />
                                <sysproperty key="maven.home" value="${maven.dir}" />
                                <args />
                                <arg line="@{target}" />
                           </java>
                      </sequential>
                 </macrodef>