创建 build.xml 个独立于库在计算机上的位置的文件

Create build.xml file independant of the location of the libraries on a computer

为了生成 war 文件,我通过 eclipse 创建了一个 build.xml 文件。 build.xml如下图:

<?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>

所以我的问题是:如何以独立于我的计算机上的库位置的方式编写此 build.xml 文件? 假设我 运行 在不包含文件夹 Oracle/Middleware 的计算机中创建此构建文件。在那种情况下,我猜它不会生成 war 文件。有没有办法让它工作?如果是这样,你能给我举个例子,或者给我看一些他们做这件事的教程。因为我对蚂蚁完全陌生。

可以存储第三方库

  • 在网络上的共享文件夹中
  • 在源代码控制系统中(git、svn、perforce)
  • 在存储库(Artifactory、nexus)中
  • 等等

在创建 war 之前,您应该获取这些库(方法取决于您选择的解决方案)并将它们放置在本地。