dimanche 31 mai 2015

Create build.xml file independant of the location of the libraries

In order to generate a war file , I've created a build.xml file via eclipse. The build.xml is as shown below:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. --><project basedir="." default="build" name="project">
    <property environment="env"/>
    <property name="ECLIPSE_HOME" value="../../../Documents/Eclipse EE/eclipse/"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.6"/>
    <property name="source" value="1.6"/>
    <path id="WebLogic System Libraries.libraryclasspath">
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.persistence_1.1.0.0_2-0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.oracle.jpa2support_1.0.0.0_2-1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/wlserver_10.3/server/lib/api.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/glassfish.jstl_1.2.0.1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.jsf_1.1.0.0_1-2.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.ejb_3.0.1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.enterprise.deploy_1.2.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.interceptor_1.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.jms_1.1.1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.jsp_1.3.0.0_2-1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.jws_2.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.activation_1.1.0.0_1-1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.mail_1.1.0.0_1-4-1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.xml.soap_1.3.1.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.xml.rpc_1.2.1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.xml.ws_2.1.1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.management.j2ee_1.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.resource_1.5.1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.servlet_1.0.0.0_2-5.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.transaction_1.0.0.0_1-1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.xml.stream_1.1.1.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.security.jacc_1.0.0.0_1-1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/javax.xml.registry_1.0.0.0_1-0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/wlserver_10.3/server/lib/wls-api.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.apache_1.3.0.1.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.i18n_1.9.0.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.logging_1.9.0.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.utils.full_1.10.0.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.utils.wrapper_1.4.0.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.utils.classloaders_2.0.0.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.common.security.providers.env_1.0.0.0_6-2-0-0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.common.security.saml2.manage_1.0.0.0_6-2-0-0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.weblogic.web.api_1.4.0.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.weblogic.rmi.client_1.11.0.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.transaction_2.7.1.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.workarea_1.8.0.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.xml.weblogic.xpath_1.5.0.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.datasource6_1.10.0.0.jar"/>
        <pathelement location="../../../../../Oracle/Middleware/modules/com.bea.core.weblogic.stax_1.10.0.0.jar"/>
    </path>
    <path id="Web App Libraries.libraryclasspath">
        <pathelement location="WebContent/WEB-INF/lib/log4j-1.2.17.jar"/>
    </path>
    <path id="EAR Libraries.libraryclasspath"/>
    <path id="project.classpath">
        <pathelement location="boum/classes"/>
        <path refid="WebLogic System Libraries.libraryclasspath"/>
        <path refid="Web App Libraries.libraryclasspath"/>
        <path refid="EAR Libraries.libraryclasspath"/>
    </path>
    <path id="run.Test.bootclasspath">
        <fileset dir="${java.home}/lib" includes="*.jar"/>
        <fileset dir="${java.home}/lib/ext" includes="*.jar"/>
        <path refid="WebLogic System Libraries.libraryclasspath"/>
    </path>
    <target name="init">
        <mkdir dir="boum/classes"/>
        <copy includeemptydirs="false" todir="boum/classes">
            <fileset dir="client">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
        <copy includeemptydirs="false" todir="boum/classes">
            <fileset dir="test">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
        <copy includeemptydirs="false" todir="boum/classes">
            <fileset dir="src">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target name="clean">
        <delete dir="boum/classes"/>
    </target>
    <target depends="clean" name="cleanall"/>
    <target depends="build-subprojects,build-project" name="build"/>
    <target name="build-subprojects"/>
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="boum/classes" includeantruntime="false" source="${source}" target="${target}">
            <src path="client"/>
            <src path="test"/>
            <src path="src"/>
            <classpath refid="project.classpath"/>
        </javac>
    </target>
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
    <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
        <copy todir="${ant.library.dir}">
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </copy>
        <unzip dest="${ant.library.dir}">
            <patternset includes="jdtCompilerAdapter.jar"/>
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </unzip>
    </target>
    <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
        <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <antcall target="build"/>
    </target>
    <target name="Test">
        <java classname="Test" failonerror="true" fork="yes">
            <classpath refid="project.classpath"/>
            <bootclasspath>
                <path refid="run.Test.bootclasspath"/>
            </bootclasspath>
        </java>
</target>
 <target name="war" description="Bundles the application as a WAR file" depends="clean, build">
            <mkdir dir="WebContent/WEB-INF/classes"/>
            <copy includeemptydirs="false" todir="WebContent/WEB-INF/classes">
                    <fileset dir="boum/classes">
                    <include name="**/**"/>
                    </fileset>
            </copy>
             
            <war destfile="boumboum.war"
                basedir="WebContent"
                needxmlfile="false">
            </war>
        </target>
</project>

So my question is: how can I write this build.xml file in a way that is independant from the location of the libraries which is my computer ? Let's say I run this build file in a computer which doesn't contains the folders Oracle/Middleware. In that case I guess it wont generate the war file. Is there a way to make it work ? If so ,could you show me an example or point me to some tutorials where they do it. Because i'm completely new with ant.

Aucun commentaire:

Enregistrer un commentaire