如何使用ant开始使用spring批处理?

时间:2016-10-26 08:40:57

标签: spring ant batch-processing

我正在学习java spring批处理,我正在尝试获取librairies,在教程中我只看到使用maven2获取librairies但我只有ant(我不能得到maven或gradle)所以我该怎么做才能依赖呢?我必须创建一个pom.xml,然后呢?

1 个答案:

答案 0 :(得分:0)

Apache ivy是一个插件,为您的ANT构建Maven超级大国提供: - )

以下是填充" lib"的retrieve task示例。 。目录

<ivy:retrieve pattern="${lib.dir}/[artifact]-[revision](-[classifier]).[ext]">
    <dependency org="org.springframework.batch" name="spring-batch-core" rev="3.0.7.RELEASE" conf="default"/>
</ivy:retrieve>

或者,您可以在单独的ivy.xml文件中指定项目的依赖项。

实施例

完整的工作示例。

├── build.xml
└── lib
    ├── aopalliance-1.0.jar
    ├── com.ibm.jbatch-tck-spi-1.0.jar
    ├── commons-logging-1.1.3.jar
    ├── javax.batch-api-1.0.jar
    ├── jettison-1.2.jar
    ├── spring-aop-4.0.5.RELEASE.jar
    ├── spring-batch-core-3.0.7.RELEASE.jar
    ├── spring-batch-infrastructure-3.0.7.RELEASE.jar
    ├── spring-beans-4.0.5.RELEASE.jar
    ├── spring-context-4.0.5.RELEASE.jar
    ├── spring-core-4.0.5.RELEASE.jar
    ├── spring-expression-4.0.5.RELEASE.jar
    ├── spring-retry-1.1.0.RELEASE.jar
    ├── spring-tx-4.0.5.RELEASE.jar
    ├── xmlpull-1.1.3.1.jar
    ├── xpp3_min-1.1.4c.jar
    └── xstream-1.4.7.jar

的build.xml

<project name="demo" default="compile" xmlns:ivy="antlib:org.apache.ivy.ant">

    <!--
    ================
    Build properties
    ================
    -->
    <property name="src.dir"          location="src/main/java"/>
    <property name="resources.dir"    location="src/main/resources"/>
    <property name="test.src.dir"     location="src/test/java"/>
    <property name="build.dir"        location="build"/>
    <property name="lib.dir"          location="lib"/>
    <property name="dist.dir"         location="${build.dir}/dist"/>

    <property name="jar.main.class" value="org.demo.App"/>
    <property name="jar.file"       value="${dist.dir}/${ant.project.name}.jar"/>

    <available classname="org.apache.ivy.Main" property="ivy.installed"/> 

    <!--
    ===============
    Compile targets
    ===============
    -->
    <target name="resolve" depends="install-ivy">
        <ivy:retrieve pattern="${lib.dir}/[artifact]-[revision](-[classifier]).[ext]">
            <dependency org="org.springframework.batch" name="spring-batch-core" rev="3.0.7.RELEASE" conf="default"/>
        </ivy:retrieve>
    </target>

    <target name="compile" depends="resolve">
    </target>

    <!--
    ===========
    Install ivy
    ===========
    -->
    <target name="install-ivy" unless="ivy.installed">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
        <fail message="Ivy has been installed. Run the build again"/>
    </target>

    <!--
    =============
    Clean targets
    =============
    -->
    <target name="clean">
        <delete dir="${build.dir}"/>
        <delete dir="${lib.dir}"/>
    </target>

    <target name="clean-all" depends="clean">
        <ivy:cleancache/>
    </target>

</project>

注意:

  • 有一个目标会安装常春藤
  • 还有一个目标可以选择清除常春藤的下载缓存。