Thank you for visiting! If you liked the site, please add a bookmark, else add a critical comment! Would you like to visit Greece? Traditional Greek flag This real estate site is only available in Greek! The holy mountain

Thursday, 19 April 2012

Farewell to ...ANT?

Following the articles by J.Stegeman and E.Biemond about building via ant scripts,  external to JDeveloper, one can quickly find out that the former does show how to create a war file, out of mostly .xml files, but not an ear; and the latter  misses on creating a war file out of the ViewController project! This article comes as supplement of both, showing how to jar the ejb3 model project,  to war the  ViewController, and lastly the external log4j library jar, assemble them in an ADF application ear and finally deploy to weblogic 10.3.4 application server.

First,  comes the model ant script:

<?xml version="1.0" encoding="UTF-8" ?>
<!--Ant buildfile runs only outside of JDeveloper-->
<!--Generated Apr 7, 2012 8:59:13 AM-->
<project name="Model" default="all" basedir=".">
  <property file="../Model/build.properties"/>
  <import file="../JDeveloperLibs/jdev-libs.xml"/>
  <path id="model.classpath">
    <pathelement location="classes"/>
    <pathelement location="../lib/log4j-1.2.15.jar"/>

    <path refid="JDeveloperLibs.library.EJB.3.0"/>
    <path refid="JDeveloperLibs.library.TopLink"/>
    <path refid="JDeveloperLibs.library.Java.EE.1.5.API"/>
    <path refid="JDeveloperLibs.library.WebLogic.10.3.Remote-Client"/>
    <path refid="JDeveloperLibs.library.ADF.Model.Runtime"/>
    <path refid="JDeveloperLibs.library.ADF.Model.Generic.Runtime"/>
    <path refid="JDeveloperLibs.library.Resource.Bundle.Support"/>
    <path refid="JDeveloperLibs.library.ADF.Common.Runtime"/>
    <!--path refid="JDeveloperLibs.library.Log4j-1.2.15.jar"/-->
    <path refid="JDeveloperLibs.library.Oracle.JDBC"/>
    <path refid="JDeveloperLibs.library.MDS.Runtime"/>
    <path refid="JDeveloperLibs.library.Oracle.XML.Parser.v2"/>
  </path>
  <target name="model.init">
    <tstamp/>
    <mkdir dir="${model.output.dir}"/>
    <mkdir dir="${model.deploy.dir}"/>
  </target>
  <target name="model.all" description="Build the project"
          depends="model.compile,model.copy"/>
  <target name="model.clean" description="Clean the project">
    <delete includeemptydirs="true" quiet="true">
      <fileset dir="${model.output.dir}" includes="**/*"/>
      <fileset dir="${model.deploy.dir}" includes="**/*"/>
    </delete>
  </target>
  <target name="model.compile" description="Compile Java source files"
          depends="model.init">
    <javac destdir="${model.output.dir}" classpathref="model.classpath"
           debug="${javac.debug}" nowarn="${javac.nowarn}"
           deprecation="${javac.deprecation}" encoding="UTF-8" source="1.6"
           target="1.6">
      <src path="../lib"/>
    </javac>
    <javac destdir="${model.output.dir}" classpathref="model.classpath"
           debug="${javac.debug}" nowarn="${javac.nowarn}"
           deprecation="${javac.deprecation}" encoding="UTF-8" source="1.6"
           target="1.6">
      <src path="${model.src.dir}"/>
    </javac>
  </target>
  <target name="model.copy" description="Copy files to output directory"
          depends="model.init">
    <patternset id="copy.patterns">
      <include name="**/*.gif"/>
      <include name="**/*.jpg"/>
      <include name="**/*.jpeg"/>
      <include name="**/*.png"/>
      <include name="**/*.properties"/>
      <include name="**/*.xml"/>
      <include name="**/*.ejx"/>
      <include name="**/*.xcfg"/>
      <include name="**/*.cpx"/>
      <include name="**/*.dcx"/>
      <include name="**/*.sva"/>
      <include name="**/*.wsdl"/>
      <include name="**/*.ini"/>
      <include name="**/*.tld"/>
      <include name="**/*.tag"/>
      <include name="**/*.xlf"/>
      <include name="**/*.xsl"/>
      <include name="**/*.xsd"/>
      <exclude name="**/persistence.xml"/>
        <exclude name="**/weblogic-ejb-jar.xml"/>
    </patternset>
    <copy todir="${model.output.dir}">
      <fileset dir="${model.src.dir}">
        <patternset refid="copy.patterns"/>
      </fileset>
      <fileset dir="../lib">
        <patternset refid="copy.patterns"/>
      </fileset>
    </copy>
    <copy todir="${model.output.dir}">
      <fileset dir="../Model/adfmsrc">
        <patternset refid="copy.patterns"/>
         <include name="../Model/adfmsrc/actionbazaar/DataControls.dcx"/>
      </fileset>
    </copy>
  </target>
  <target name="model.jar" depends="model.compile,model.copy">
    <jar destfile="${model.deploy.dir}/${model.jar.file}" >
      <fileset dir="${model.output.dir}">
        <include name="**/*.class"/>
        <include name="**/*.xml"/>
        <include name="**/*.dcx"/>
         <exclude name="**/*.java"/>
        <exclude name="**/**/actionbazaar/buslogic/client/**"/>
      </fileset>
      <fileset dir="${model.src.dir}/">
        <include name="META-INF/persistence.xml"/>
        <include name="META-INF/**"/>
        <include name="**/*.xml"/>
        <include name="**/*.dcx"/>
        <include name="**/*.properties"/>
        <exclude name="**/*.java"/>
        <exclude name="**/build.xml"/>
        <exclude name="**/build.properties"/>
      </fileset>
    </jar>
  </target>
</project>

Second, the userinterface or ViewController one:

<?xml version="1.0" encoding="UTF-8" ?>
<!--Generated Apr 7, 2012 9:24:35 AM-->
<project name="UserInterface" default="UserInterface.ear" basedir=".">
  <taskdef name="wldeploy"
           classname="weblogic.ant.taskdefs.management.WLDeploy"/>
  <taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
      <pathelement location="${ant.lib.folder}/lib/ant-contrib.jar"/>
    </classpath>
  </taskdef>
  <property file="../UserInterface/build.properties"/>
  <import file="../JDeveloperLibs/jdev-libs.xml"/>
  <import file="../Model/build.xml"/>
  <import file="Datasource.xml"/>
  <path id="UserInterface.classpath">
    <pathelement location="../Model/classes"/>
    <pathelement location="../lib/log4j-1.2.15.jar"/>
    <!--path refid="JDeveloperLibs.library.JSTL.1.2"/-->
    <path refid="JDeveloperLibs.library.JSTL.1.2.Tags"/>
    <path refid="JDeveloperLibs.library.JSF.1.2"/>
    <path refid="JDeveloperLibs.library.ADF.Faces.Runtime.11"/>
    <path refid="JDeveloperLibs.library.ADF.Common.Runtime"/>
    <path refid="JDeveloperLibs.library.JSP.Runtime"/>
    <path refid="JDeveloperLibs.library.ADF.DVT.Core.Runtime"/>
    <path refid="JDeveloperLibs.library.ADF.DVT.Faces.Runtime"/>
    <path refid="JDeveloperLibs.library.ADF.DVT.Faces.Databinding.Runtime"/>
    <path refid="JDeveloperLibs.library.ADF.Faces.Databinding.Runtime"/>
    <path refid="JDeveloperLibs.library.ADF.Page.Flow.Runtime"/>
    <path refid="JDeveloperLibs.library.ADF.Model.Runtime"/>
    <path refid="JDeveloperLibs.library.ADF.Controller.Runtime"/>
    <path refid="JDeveloperLibs.library.ADF.Web.Runtime"/>
    <path refid="JDeveloperLibs.library.MDS.Runtime"/>
    <path refid="JDeveloperLibs.library.EJB.Data.Control"/>
    <path refid="JDeveloperLibs.library.EJB.3.0"/>
    <path refid="JDeveloperLibs.library.TopLink"/>
    <path refid="JDeveloperLibs.library.Java.EE.1.5.API"/>
    <path refid="JDeveloperLibs.library.WebLogic.10.3.Remote-Client"/>
    <path refid="JDeveloperLibs.library.Resource.Bundle.Support"/>
    <path refid="JDeveloperLibs.library.ADF.Controller.Schema"/>
    <path refid="JDeveloperLibs.library.MDS.Runtime.Dependencies"/>
    <path refid="JDeveloperLibs.library.Commons.Beanutils.1.6"/>
    <path refid="JDeveloperLibs.library.Commons.Logging.1.0.4"/>
    <path refid="JDeveloperLibs.library.Commons.Collections.3.1"/>
    <path refid="JDeveloperLibs.library.ADF.DVT.Faces.Databinding.MDS.Runtime"/>
    <path refid="JDeveloperLibs.library.Oracle.JDBC"/>
    <path refid="JDeveloperLibs.library.Oracle.JEWT"/>
    <path refid="JDeveloperLibs.library.BC4J.Security"/>
    <path refid="JDeveloperLibs.library.ADF.Common.Web.Runtime"/>
    <path refid="JDeveloperLibs.library.Servlet.Runtime"/>
    <path refid="JDeveloperLibs.library.Resource.Bundle.Variable.Resolver"/>
    <path refid="JDeveloperLibs.library.Trinidad.Runtime.11"/>
    <path refid="JDeveloperLibs.library.Trinidad.Databinding.Runtime"/>
  </path>
  <target name="UserInterface.init">
    <tstamp/>
    <mkdir dir="${UserInterface.output.dir}"/>
    <mkdir dir="${UserInterface.deploy.dir}"/>
  </target>
  <target name="UserInterface.all" description="Build the project"
          depends="UserInterface.compile,UserInterface.copy"/>
  <target name="UserInterface.clean" description="Clean the project">
    <delete includeemptydirs="true" quiet="true">
      <fileset dir="${UserInterface.output.dir}" includes="**/*"/>
      <fileset dir="${UserInterface.deploy.dir}" includes="**/*"/>
      <fileset dir="${model.output.dir}" includes="**/*"/>
      <fileset dir="${model.deploy.dir}" includes="**/*"/>
    </delete>
  </target>
  <target name="UserInterface.compile" description="Compile Java source files"
          depends="UserInterface.init,model.compile">
    <javac destdir="${UserInterface.output.dir}"
           classpathref="UserInterface.classpath" debug="${javac.debug}"
           nowarn="${javac.nowarn}" deprecation="${javac.deprecation}"
           encoding="UTF-8" source="1.6" target="1.6">
      <src path="../lib"/>
    </javac>
    <javac destdir="${UserInterface.output.dir}"
           classpathref="UserInterface.classpath" debug="${javac.debug}"
           nowarn="${javac.nowarn}" deprecation="${javac.deprecation}"
           encoding="UTF-8" source="1.6" target="1.6">
      <src path="${UserInterface.src.dir}"/>
    </javac>
  </target>
  <target name="UserInterface.copy" description="Copy files to output directory"
          depends="UserInterface.init">
    <patternset id="copy.patterns">
      <include name="**/*.jspx"/>
      <include name="**/*.gif"/>
      <include name="**/*.jpg"/>
      <include name="**/*.jpeg"/>
      <include name="**/*.png"/>
      <include name="**/*.properties"/>
      <include name="**/*.xml"/>
      <include name="**/*.ejx"/>
      <include name="**/*.xcfg"/>
      <include name="**/*.cpx"/>
      <include name="**/*.dcx"/>
      <include name="**/*.sva"/>
      <include name="**/*.wsdl"/>
      <include name="**/*.ini"/>
      <include name="**/*.tld"/>
      <include name="**/*.tag"/>
      <include name="**/*.xlf"/>
      <include name="**/*.xsl"/>
      <include name="**/*.xsd"/>
      <include name="**/*.sso"/>
    </patternset>
    <patternset id="webfile.patterns">
      <include name="**/*.html"/>
      <include name="**/*.jspx"/>
      <include name="**/images/*.jpg"/>
    </patternset>
    <patternset id="webinf.patterns">
      <include name="WEB-INF/**/*.xml"/>
      <include name="**/WEB-INF/lib/*.jar"/>
    </patternset>
    <patternset id="library.patterns">
      <!--include name="**/glassfish.jsf_1.0.0.0_1-2-15.jar"/>
      <include name="**/glassfish.jstl_1.2.0.1.jar"/>
      <include name="**/javax.jsf_1.1.0.0_1-2.jar"/>
      <include name="**/wls.jsf.di.jar"/-->
      <include name="**/log4j-1.2.15.jar"/>
      <include name="**/adf-loc.jar"/>
      <exclude name="**/modules/javax.jsf_1.1.0.0_1-2.jar"/>
    </patternset>
    <copy todir="${UserInterface.output.dir}">
      <fileset dir="${UserInterface.src.dir}">
        <patternset refid="copy.patterns"/>
      </fileset>
      <fileset dir="../lib">
        <patternset refid="copy.patterns"/>
      </fileset>
    </copy>
    <copy todir="${UserInterface.output.dir}">
      <fileset dir="../UserInterface/adfmsrc">
        <patternset refid="copy.patterns"/>
      </fileset>
    </copy>
  </target>
  <target name="UserInterface.war"
          depends="UserInterface.copy,UserInterface.compile,model.copy">
    <war destfile="${UserInterface.deploy.dir}/${UserInterface.war.file}"
         webxml="${UserInterface.html.dir}/WEB-INF/web.xml">
      <zipfileset dir="${UserInterface.html.dir}">
        <patternset refid="webinf.patterns"/>
      </zipfileset>
      <zipfileset dir="${UserInterface.html.dir}">
        <patternset refid="webfile.patterns"/>
      </zipfileset>
      <zipfileset dir="${UserInterface.output.dir}" prefix="WEB-INF/classes">
        <exclude name=".data/**"/>
        <exclude name="**/*.cdi"/>
        <exclude name="**/build.xml"/>
        <exclude name="**/build.properties"/>
        <exclude name="**/*.java"/>
        <exclude name="**/log4j-1.2.15.jar"/>
        <exclude name="**/WEB-INF/temp/**"/>
      </zipfileset>
    </war>
  </target>
  <target name="UserInterface.ear" depends="UserInterface.war,model.jar">
    <mkdir dir="${UserInterface.deploy.dir}\META-INF"/>
    <mkdir dir="${UserInterface.deploy.dir}\lib"/>
    <copy todir="${UserInterface.deploy.dir}\lib">
      <zipfileset file="..\lib\*.jar" prefix="lib"/>
    </copy>
      <copy todir="${UserInterface.deploy.dir}\META-INF">
         <fileset dir="${project.src.dir}\META-INF" excludes="application.xml"
               includes="cwallet.sso">
        <patternset refid="copy.patterns"/>
      </fileset>
    </copy>
    <copy todir="${UserInterface.deploy.dir}\adf\META-INF">
      <fileset dir="..\.adf\META-INF">
        <patternset refid="copy.patterns"/>
      </fileset>
    </copy>
    <copy file="${UserInterface.deploy.dir}/${UserInterface.war.file}"
          todir="${UserInterface.deploy.dir}"/>
    <copy file="${model.deploy.dir}/${model.jar.file}"
          todir="${UserInterface.deploy.dir}"/>
    <ear basedir="${UserInterface.deploy.dir}"
         destfile="${UserInterface.deploy.dir}/${UserInterface.ear.file}"
         appxml="${project.src.dir}/META-INF/application.xml">
      <zipfileset dir="../JDeveloperLibs" prefix="lib">
        <patternset refid="library.patterns"/>
      </zipfileset>
          </ear>
  </target>
  <target name="UserInterface.autodeploy" depends="UserInterface.ear">
    <copy file="${UserInterface.deploy.dir}/${UserInterface.ear.file}"
          todir="${weblogic.home}/${weblogic.deploy.dir}"/>
  </target>
  <target name="UserInterface.deploy"
          depends="UserInterface.clean,UserInterface.ear,JDBC">
    <echo message="Start undeploying application..."></echo>
    <wldeploy action="undeploy" verbose="true" debug="true" name="${project}"
              adminurl="t3://${host}:${port}" user="${username}"
              password="${password}" targets="${target.server}"
              failonerror="false"/>
    <wldeploy action="deploy" verbose="true" debug="true" name="${project}"
              adminurl="t3://${host}:${port}" user="${username}"
              password="${password}" targets="${target.server}"
              failonerror="false"
              source="${UserInterface.deploy.dir}/${UserInterface.ear.file}"
              remote="true" upload="true"/>
    <echo message="END OF DEPLOYING APPLICATION"></echo>
  </target>
</project>


Finally, a word of caution: using ant nowdays seems to many people a waste of time or efford, when compared to modern solutions such as maven, well presented here by Dana Singleterry. As usual, one can find far more information, including source code, below.

REFERENCES
http://biemond.blogspot.com/2009/04/weblogic-jdeveloper-ant-tasks.html
http://www.oracle.com/technetwork/articles/adf/part4-098813.html
http://tompeez.wordpress.com/2012/02/07/jdeveloper-gem-debug-ant-scripts by Timo Hahn